child-process

node.js run function in child process?

…衆ロ難τιáo~ 提交于 2019-12-05 07:26:29
I have a node.js application that receives a file, via a web request and then will apply a conversion process to this file. Since the task is long running this needs to run separate to the main thread. At the moment I have just called the necessary code via a setTimeout() call. To isolate the main application from the conversion process I would like to move it out into a child process, since it is long running and I would like to isolate the main code from the work being done (am I worrying too much?). At the moment I am calling: const execFile = require('child_process').execFile; const child

Do I have to close inherited handle later owned by child process?

走远了吗. 提交于 2019-12-05 03:38:04
Microsoft played safe here. In their article, "Creating a Child Process with Redirected Input and Output" , they are saying: The remaining open handles are cleaned up when this process terminates. To avoid resource leaks in a larger application, close handles explicitly. Which is perfectly useless. What handles? In which process? I want to get my head around it. When a handle is created in parent process with SECURITY_ATTRIBUTES.bInheritHandle = TRUE , a child process can see and use it, and the handle has the same value and access rights in both processes. But is it the same handle, or is it

Nodejs child_process spawn custom stdio

感情迁移 提交于 2019-12-05 03:23:25
I would like to use custom stream to handle child_process.spawn stdio. For example const cp = require('child_process'); const process = require('process'); const stream = require('stream'); var customStream = new stream.Stream(); customStream.on('data', function (chunk) { console.log(chunk); }); cp.spawn('ls', [], { stdio: [null, customStream, process.stderr] }); I get error Incorrect value for stdio stream . There is documentation for child_process.spawn https://nodejs.org/api/child_process.html#child_process_options_stdio . It says for stdio options that it can take Stream object Stream

It is possible to get the progress of a spawned process from nodejs?

我怕爱的太早我们不能终老 提交于 2019-12-04 19:01:46
I'm spawning npm install -g create-react-app from a js script. I want to know if it's possible to get the progress of the installation using spawn . const npmExecutable = /^win/.test(process.platform) ? "npm.cmd" : "npm"; const npm = spawn(npmExecutable, ["install", "-g", "create-react-app"]); I have read this question about using: npm.on("message", data => { console.log(`A message: ${data}`); }); but it does not show anything. There is a related question , about knowing the progress of a python script, but it does not have any answers. Does someone of you have tried something like that or

child_process.fork not starting an express server inside of packaged electron app

自古美人都是妖i 提交于 2019-12-04 17:40:25
问题 I have an electron app where I need not only to run the interface to the user but also start an express server that will serve files for people connected through the network. I have everything working if I start both electron and the express server normally, but I'm pretty confident that I will need the server running in a different thread to avoid slugish interface and even problems with the server. For that matter I tried to run my express server using the child_process.fork and it worked

node.js child_process.spawn no stdout unless 'inherit'

天涯浪子 提交于 2019-12-04 11:25:35
问题 I'm trying to capture the stdout from a spawn ed child_process in node.js (0.10.29). Right now I'm just trying with ping The following code doesn't print (but does ping) var exec = require('child_process').exec; var spawn = require('child_process').spawn; var util = require('util') var ping = spawn('ping', ['127.0.0.1'], {stdio: 'pipe'}); ping.stdout.on('data', function(data){ util.print(data); }) ping.stderr.on('data', function(data){ util.print(data); }) If I change stdio: 'pipe' to stdio:

How to prevent console from being displayed when using VLC's dummy interface

你。 提交于 2019-12-04 04:52:48
问题 I'm trying to launch VLC in "dummy" mode from a Node.js server script, however using child_process.spawn('vlc',['-I dummy']) produces a new console window for VLC's output when using Windows. Is there a way to prevent this happening and force all stdout though the stdout ReadableStream so no "popup windows" occur? EDIT : This problem had nothing to do with node.js, it was simply the way I was calling it and VLC's behaviour. The solution is below. Thanks. 回答1: I found a solution for the

How to pass function/callback to child process in Node.js?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 04:33:26
Let's say I have a parent.js containing a method named parent var childProcess = require('child_process'); var options = { someData: {a:1, b:2, c:3}, asyncFn: function (data, callback) { /*do other async stuff here*/ } }; function Parent(options, callback) { var child = childProcess.fork('./child'); child.send({ method: method, options: options }); child.on('message', function(data){ callback(data,err, data,result); child.kill(); }); } Meanwhile in child.js process.on('message', function(data){ var method = data.method; var options = data.options; var someData = options.someData; var asyncFn =

Stripe with React JS

和自甴很熟 提交于 2019-12-04 02:41:44
I need to create token with Stripe.js in React JS, but I can't find any easy way. In node.js I would do something like this: stripeClient.tokens.create({ card: { number: '4242424242424242', exp_month: 12, exp_year: 2050, cvc: '123' } But the Stripe npm module doesn't work for me in React JS. I'm getting error: Cannot resolve module 'child_process' So since this is node pibrary obviously, I would like to use <script type="text/javascript" src="https://js.stripe.com/v2/"></script> But I'm not sure what should be the best practice to implement external libraries in React You can just go ahead and

How can I make Perl wait for child processes started in the background with system()?

孤街浪徒 提交于 2019-12-04 02:20:34
I have some Perl code that executes a shell script for multiple parameters, to simplify, I'll just assume that I have code that looks like this: for $p (@a){ system("/path/to/file.sh $p&"); } I'd like to do some more things after that, but I can't find a way to wait for all the child processes to finish before continuing. Converting the code to use fork() would be difficult. Isn't there an easier way? Using fork/exec/wait isn't so bad: my @a = (1, 2, 3); for my $p (@a) { my $pid = fork(); if ($pid == -1) { die; } elsif ($pid == 0) { exec '/bin/sleep', $p or die; } } while (wait() != -1) {}