![]() ![]() ![]() For example: const childProcess = require('child_process') Ĭonst osInfo = childProcess.execSync('uname -a').toString() Ĭonst files = childProcess.execSync('ls -a'). The standard approach is to not care about re-using a process or shell and letting NodeJS just spawn & kill them automatically. In your initial example the executed bash is given the '> /out/put/log' stuff as its last argument, which it isn't supposed to be. So to simply open an application with PowerShell we could use the following command: Start-Process Notepad.exe Simply typing notepad.exe in PowerShell will have the same result: Notepad.exe This will open Notepad in a new window with the same privileges as the PowerShell session. The events are: Class: ChildProcess Event: error Event: exit Event: close Event: disconnect Event: message There are also a bunch of objects from childObject, they are: Class: ChildProcess child. Execute ls -a to list files in the current directory posixspawn(&pid, '/bin/bash', NULL, NULL, argv, environ) Yes it could all be done more effectively, but like this you wouldn't need to do the piping in your program. Redirecting a shells stdandard fds from other files does NOT detach it from the controlling terminal. 10 Answers Sorted by: 212 Its much easier now (6 years later) Spawn returns a childObject, which you can then listen for events with.Throughout this post, I’ll use this as the sample scenario: Sub RunProgram Set objShell CreateObject(Wscript.Shell) objShell.Run notepad.exe c:scriptstest. a wrapper for the screen program that bundles additional functionality and custom plugins for an enhanced experience working in the terminal. Is there a way to spawn a shell in NodeJS, keep it open, and reuse it for multiple commands (perhaps even calling different binaries)? ![]() I’m making this post because this question has been bugging me, and I have had an unreasonably difficult time finding information on it. ![]()
0 Comments
Leave a Reply. |