spawn

nodejs/express - stream stdout instantly to the client

橙三吉。 提交于 2019-12-03 18:40:36
问题 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

What is the difference between spawn and exec?

最后都变了- 提交于 2019-12-03 00:00:28
I'm learning to write a TCL (expect) scripts and I notice that some examples show to use spawn, while others show the command exec. I tried googling, but can't find what is the difference? Suppose I call 'exec' in a middle of a long expect script, what can I expect to happen? spawn is an expect command not a tcl command. exec is a tcl command. spawn creates a process. The processes' input and output are connected to expect for use by the other expect commands: send , expect and interact . exec creates a subprocess under tcl. In general the tcl is suspended until the subprocess completes.

Spawn in nodejs for a unix command with spaces in parameters

巧了我就是萌 提交于 2019-12-02 21:15:50
问题 I would like to execute the following command using nodejs Spawn on a Debian system : /usr/bin/apt-get upgrade -s | tail -1 | cut -f1 -d' ' I want to use spawn and not exec because of future use of root only commands and i don't want to allow a full shell access (i will update the visudo file with correct commands) Here is my code const apt = spawn('/usr/bin/apt-get', ['upgrade', '-s']); const tail = spawn('tail', ['-1']); const cut = spawn('cut', ['-f1', '-d" "']); apt.stdout.on('data',

php forking issue

好久不见. 提交于 2019-12-02 17:05:38
问题 I have the following test php to do a fork/spawn process, where the test also attempts to kill the child process (zombie) after is completes.. I'd like to have a more efficient process, where any child processes are immediately removed from the process table as soon as possible. The current attempt fills up the process table, and causes a memory allocation issue that shuts down the system. The app is running on a Fedora/Centos system. I'm running into a memory allocation err when this runs,

Uncaught Error: spawn .\node.exe ENOENT

强颜欢笑 提交于 2019-12-02 10:40:03
问题 I have a nodejs app being run through electron https://github.com/frankhale/electron-with-express After packaging the app as an executable using npm run dist:win32 , I ran into the following issue in console: events.js:160 Uncaught Error: spawn .\node.exe ENOENT Below is how my devDependencies looks like "devDependencies": { "electron-builder": "^5.26.0", "electron-prebuilt": "^1.3.3", "electron-rebuild": "^1.2.0" } When i run the app using npm start it works fine, and no error is run. Its

Twisted Python: Cannot write to a running spawned process

我的未来我决定 提交于 2019-12-02 10:37:56
问题 My question is, after spawning a process, the child process is looping to get data from its stdin. I would like to write new data to it using either Echo.Process.pipes[0].write(data) or Echo.Process.writeToChild(0,data), but both do not work. Would someone explain what's going on? Or how do I go around this problem? This is the error I got: --- <exception caught here> --- File "/usr/local/encap/python-2.6.4/lib/python2.6/site-packages/Twisted-9.0.0-py2.6-linux-x86_64.egg/twisted/internet

Spawn in nodejs for a unix command with spaces in parameters

坚强是说给别人听的谎言 提交于 2019-12-02 10:03:53
I would like to execute the following command using nodejs Spawn on a Debian system : /usr/bin/apt-get upgrade -s | tail -1 | cut -f1 -d' ' I want to use spawn and not exec because of future use of root only commands and i don't want to allow a full shell access (i will update the visudo file with correct commands) Here is my code const apt = spawn('/usr/bin/apt-get', ['upgrade', '-s']); const tail = spawn('tail', ['-1']); const cut = spawn('cut', ['-f1', '-d" "']); apt.stdout.on('data', (data) => { tail.stdin.write(data); }); tail.stdout.on('data', (data) => { cut.stdin.write(data); }); cut

php forking issue

混江龙づ霸主 提交于 2019-12-02 08:15:40
I have the following test php to do a fork/spawn process, where the test also attempts to kill the child process (zombie) after is completes.. I'd like to have a more efficient process, where any child processes are immediately removed from the process table as soon as possible. The current attempt fills up the process table, and causes a memory allocation issue that shuts down the system. The app is running on a Fedora/Centos system. I'm running into a memory allocation err when this runs, and there are too many processes that get spawned, before they get removed. Any pointers would be

Twisted Python: Cannot write to a running spawned process

微笑、不失礼 提交于 2019-12-02 07:37:00
My question is, after spawning a process, the child process is looping to get data from its stdin. I would like to write new data to it using either Echo.Process.pipes[0].write(data) or Echo.Process.writeToChild(0,data), but both do not work. Would someone explain what's going on? Or how do I go around this problem? This is the error I got: --- <exception caught here> --- File "/usr/local/encap/python-2.6.4/lib/python2.6/site-packages/Twisted-9.0.0-py2.6-linux-x86_64.egg/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite why = getattr(selectable, method)() File "/usr/local/encap

How do I obtain the PID of a spawned java process

只愿长相守 提交于 2019-12-02 07:13:35
问题 I am writing several java programs and will need to kill off/clean up in a seperate JVM after I am done with whatever I wanted to do. For this, I will need to get the PID of the java process which I am creating. 回答1: jps -l works both on Windows and Unix. You can invoke this command from your java program using Runtime.getRuntime().exec . Sample output of jps -l is as follows 9412 foo.bar.ClassName 9300 sun.tools.jps.Jps You might need to parse this and then check for the fully qualified name