Hide child process console window
Asked Answered
M

4

28

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.

Marielamariele answered 15/7, 2015 at 15:37 Comment(11)
possible duplicate of How to prevent console from being displayed when using VLC's dummy interfaceRemains
The duplicate nor Node's documentation mention a way to do this through your code. Perhaps you can configure the client application through commandline parameters that it shouldn't show a window. If you run Node as a Windows Service you won't see the windows anyway.Remains
I use spawn and I never get a separate window on windows. Thjo i have listeneras setup for stdout and stderr. maybe thats the reason (i am not sure)... but I guess it depends on what are you invoking in your spawn.Objurgate
I have the same problem with exec.Marielamariele
@Marielamariele have you actually tried putting listeners for stdout and stderr for data? I am talking about spawn.Objurgate
Yes I have tried that.Marielamariele
I am surprised why the window doesn't come up for me.Objurgate
The problem is specifically related to forever vs. running node yourself on the command line and leaving it. It only happens with forever for me. spawn and exec both do it.Desai
how about using cluster?Disenthrall
nodejs.org/api/… describes windowsHide <boolean>: "Hide the subprocess console window that would normally be created on Windows systems. Default: false."Show
windowsHide won't work with the option detached: true because of this bug github.com/nodejs/node/issues/21825Newfeld
S
1

In 2017, a windowsHide option was introduced:

Hide the subprocess console window that would normally be created on Windows systems. Default: false.

Show answered 5/8, 2021 at 9:58 Comment(0)
V
0

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
Vivisectionist answered 1/9, 2016 at 8:55 Comment(0)
R
0

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.

Ricciardi answered 24/10, 2017 at 0:28 Comment(0)
F
0

use detached property like

spawn('node', [filePath, args], {
            detached: true,
            stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
        })
Flatcar answered 30/6, 2021 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.