child-process

Node.js pass handle of response object handle to child process

社会主义新天地 提交于 2019-12-01 03:33:59
I have an http server and a forked child process. I want the parent to receive requests and pass to forked process using worker.send . and the worker should be able to process and send the response back to the requester using the same response object. I tried sending the response object in the second parameter of worker.send , but it gives the error This handle type can't be sent var child_process = require('child_process'); var worker = child_process.fork(filename); http.createServer(function (req, res) { worker.send({ 'event': 'start' }, res); // send response object }).listen(4000); I

Node.js pass handle of response object handle to child process

孤者浪人 提交于 2019-12-01 01:04:34
问题 I have an http server and a forked child process. I want the parent to receive requests and pass to forked process using worker.send . and the worker should be able to process and send the response back to the requester using the same response object. I tried sending the response object in the second parameter of worker.send , but it gives the error This handle type can't be sent var child_process = require('child_process'); var worker = child_process.fork(filename); http.createServer

How to see stdout of a phantomjs child process using node.js?

≡放荡痞女 提交于 2019-11-30 23:31:24
In the following node.js code, I normally have to wait for the phantomjs child process to terminate to get the stdout. I am wondering if there is any way to see the stdout while the phantomjs child process is running? var path = require('path') var childProcess = require('child_process') var phantomjs = require('phantomjs') var binPath = phantomjs.path var childArgs = [ path.join(__dirname, 'phantomjs-script.js'), ] childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) { // handle results }) You can spawn PhantomJS as a child process and subscribe to its stdout and stderr

Node.JS child processes being killed when parent dies

夙愿已清 提交于 2019-11-30 23:01:08
问题 I am using child_process.spawn() to start a script from my Node.JS application running on Ubuntu. As far as I know, standard forked or spawned *nix processes don't generally die when the parent dies, but when spawning processes from Node.JS, they seem to get killed when my application crashes, or is aborted with ctrl-c etc. Why is this and is there a way around this? I can't seem to find any obvious option in the child_process API. My application starts some quite long-running tasks that

Nodejs - process hangs on exit (Ctrl+C)

雨燕双飞 提交于 2019-11-30 11:12:28
I have a node.js project which does many things, it spawns child processes, it opens an http and socket.io server, etc.. When I run it from the console, closing it with Ctrl+C , it just hangs. From webstorm, stopping the process is a two-step process, first I hit stop, then I need to hit the button again, only the second time the button is a skull icon. Now, I understand it leaves something open or hanging, but I just can't figure out what, I tried to track all the places where I start a process and made sure I'm killing them properly. Is there a way to debug this and find out what's making my

Writing to child process file descriptor

蓝咒 提交于 2019-11-30 10:27:31
I have a program "Sample" which takes input both from stdin and a non-standard file descriptor (3 or 4) as shown below int pfds[2]; pipe(pfds); printf("%s","\nEnter input for stdin"); read(0, pO, 5); printf("\nEnter input for fds 3"); read(pfds[0], pX, 5); printf("\nOutput stout"); write(1, pO, strlen(pO)); printf("\nOutput fd 4"); write(pfds[1], pX, strlen(pX)); Now i have another program "Operator" which executes the above program(Sample) in a child process using execv. Now what i want is to send input to "Sample" through the "Operator" . After forking the child process, but before calling

Use child_process.execSync but keep output in console

元气小坏坏 提交于 2019-11-30 10:17:01
问题 I'd like to use the execSync method which was added in NodeJS 0.12 but still have the output in the console window from which i ran the Node script. E.g. if I run a NodeJS script which has the following line I'd like to see the full output of the rsync command "live" inside the console: require('child_process').execSync('rsync -avAXz --info=progress2 "/src" "/dest"'); I understand that execSync returns the ouput of the command and that I could print that to the console after execution but

Write to spawned process stdin nodejs?

会有一股神秘感。 提交于 2019-11-30 04:58:35
I have a script that I want to run from another one. The problem is that the child script (process) needs an user input before it continues. var child = spawn('script'); child.stdin.setEncoding('utf8'); child.stdout.on('data', function (data) { console.log(data.toString().trim()); // tells me to input my data child.stdin.write('my data\n'); }); After I input my data the child script should continue but instead it hang in there. Solution Actually the above code work for me. I'm using commander.js in the child script to prompt the user for action. Here is how I respond to a child's script prompt

NodeJs child_process working directory

╄→尐↘猪︶ㄣ 提交于 2019-11-30 04:39:05
I am trying to execute a child process in a different directory then the one of its parent. var exec = require('child_process').exec; exec( 'pwd', { cdw: someDirectoryVariable }, function(error, stdout, stderr) { // ... } ); I'm doing the above (though of course running "pwd" is not what I want to do in the end). This will end up writing the pwd of the parent process to stdout, regardless of what value I provided to the cdw option. What am I missing? (I did make sure the path passed as cwd option actually exists) The option is short for current working directory , and is spelled cwd , not cdw

nodejs/express - stream stdout instantly to the client

时光怂恿深爱的人放手 提交于 2019-11-30 00:22:08
I spawned the following child: var spw = spawn('ping', ['-n','10', '127.0.0.1']) and I would like to receive the ping results on the client side ( browser ) one by one , not as a whole. So far I tried this: app.get('/path', function(req, res) { ... spw.stdout.on('data', function (data) { var str = data.toString(); res.write(str + "\n"); }); ... } and that: ... spw.stdout.pipe(res); ... In both cases browser waits 10 of the pings to complete, and then prints the result as a whole. I would like to have them one by one, how to accomplish that? (Client is just making a call to .../path and console