最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hide child process console window - Stack Overflow

programmeradmin0浏览0评论

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.

Share Improve this question edited Jul 15, 2015 at 15:57 ronag asked Jul 15, 2015 at 15:37 ronagronag 51.3k26 gold badges132 silver badges229 bronze badges 11
  • 1 possible duplicate of How to prevent console from being displayed when using VLC's dummy interface – CodeCaster Commented Jul 15, 2015 at 15:41
  • 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. – CodeCaster Commented Jul 15, 2015 at 15:42
  • 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. – Gyandeep Commented Jul 15, 2015 at 16:01
  • 1 I am surprised why the window doesn't come up for me. – Gyandeep Commented Jul 15, 2015 at 19:08
  • 3 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. – Brent Commented Jul 20, 2015 at 14:55
 |  Show 6 more comments

4 Answers 4

Reset to default 1

In 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'],
        })
发布评论

评论列表(0)

  1. 暂无评论