When spawning a new child in nodejs on windows (child_process.spawn
) it always opens a blank console window which stays open until the child process ends.
Is there a way to avoid this?
i.e. we want to run our application as a background service using forever
. However, it is not very backgroundy since it keeps opening and closing blank console windows...
EDIT: Making the sub application run in "quiet" mode is not an option since parts of the processes being spawned is wmic
.
When spawning a new child in nodejs on windows (child_process.spawn
) it always opens a blank console window which stays open until the child process ends.
Is there a way to avoid this?
i.e. we want to run our application as a background service using forever
. However, it is not very backgroundy since it keeps opening and closing blank console windows...
EDIT: Making the sub application run in "quiet" mode is not an option since parts of the processes being spawned is wmic
.
4 Answers
Reset to default 1In 2017, a windowsHide
option was introduced:
Hide the subprocess console window that would normally be created on Windows systems. Default:
false
.
This way forever will spawn one console for the app. And not open for each spawn a console window.
forever -c "cmd /c node" start app.js
Following on from RanP's answer,
forever start --uid "foo" -c "cmd /c node" app.js
You'll need 'start' before your -c args and --uid is optional. Note there is one less space in the -c command, allowing this to work.
use detached
property like
spawn('node', [filePath, args], {
detached: true,
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
})
spawn
and I never get a separate window on windows. Thjo i have listeneras setup forstdout
andstderr
. maybe thats the reason (i am not sure)... but I guess it depends on what are you invoking in your spawn. – Gyandeep Commented Jul 15, 2015 at 16:01