Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A shell is spawning every time we spawn a child process on Windows #7653

Closed
vmarchaud opened this issue Jul 11, 2016 · 12 comments
Closed

A shell is spawning every time we spawn a child process on Windows #7653

vmarchaud opened this issue Jul 11, 2016 · 12 comments
Labels
child_process Issues and PRs related to the child_process subsystem. question Issues that look for answers. windows Issues and PRs related to the Windows platform.

Comments

@vmarchaud
Copy link
Contributor

vmarchaud commented Jul 11, 2016

  • Version: from 0.10 to 6.2
  • Platform: Windows

When spawning a child process with ``require('child_process').spawn`, a shell spawn for few milliseconds (almost one seconds) on Windows.
pm2's users are reporting us this issue (here or here) , which come from this code that we are using to spawn the user app.
Just asking why it is spawning and if we can prevent them to spawn ?

Thanks !

@Fishrock123 Fishrock123 added child_process Issues and PRs related to the child_process subsystem. question Issues that look for answers. windows Issues and PRs related to the Windows platform. labels Jul 11, 2016
@Fishrock123
Copy link
Contributor

See https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_child_process_spawn_command_args_options -- make sure the shell option is false.

Let me know if it is false but still spawning a shell. I'm unsure but it could be necessary. Or, it may be how spawn() has to work on windows, exec() may not have the issue. Not sure.

@vmarchaud
Copy link
Contributor Author

vmarchaud commented Jul 11, 2016

As you can see here, and as the documentation tell Defaults to false (no shell), we spawn with the shell set to false.
So no, its still spawning a shell, i will try asap with exec (as i remember its spawning a shell too, but not sure, i will re-test)

@bnoordhuis
Copy link
Member

When spawning a child process with `require('child_process').spawn, a shell spawn for few milliseconds (almost one seconds) on Windows.

When you say 'spawns a shell', do you mean it opens a console window?

@vmarchaud
Copy link
Contributor Author

@bnoordhuis Yes

@bnoordhuis
Copy link
Member

Right. That's a property of the executable you are spawning and not something node.js has direct control over. Closing, not a bug.

@vmarchaud
Copy link
Contributor Author

@bnoordhuis We are spawning the node executable by default like you can see here when spawning an app, same behavior happening here, but no console window popup with npm here.
So i believe this behavior is linked to node, could you verify that it doesnt come from node itself ?

@cjihrig
Copy link
Contributor

cjihrig commented Jul 11, 2016

You aren't running npm with detached. That could be why.

@bnoordhuis
Copy link
Member

It's a flag in the PE header of the .exe that controls whether a console window is opened or not. IOW, whether an application is a console application or not is something that is decided at compile time.

You can suppress it up to a point by passing { detached: true } to spawn() but there is nothing stopping the child process from creating a console window manually or spawning children that create one.

@wayofthefuture
Copy link

We are using childProcess.fork().
When we run "node myapp.js" from the command line, everything is fine.
When we run "pm2 start myapp.js", cmd windows pop up everywhere.

I find it hard to believe people aren't having major problems with this. The pm2 behavior does not mimic the node behavior. Trying to push a production app onto a windows device is no longer possible with pm2 as continual popups are not an option.

Whether it is a bug or not is inconsequential. The point is: there has to be a way around this problem.
Thanks

@j3ko
Copy link

j3ko commented Sep 6, 2017

@wayofthefuture did you ever find a solution to your issue? I seem to have the same problem. Straight running the app using "node app.js" works but running the app in pm2 spawns consoles.

@wayofthefuture
Copy link

Yup! Here's the solution:

https://github.com/kohsuke/winsw

I ran into problems with pm2 in both linux and windows. So now I use systemd and winsw and no longer use pm2, just straight up node myapp.js using a service... not to mention the permission problems and startup problems involved with cross-platform implementation of pm2.

@vmarchaud
Copy link
Contributor Author

Looks like someone has opened a new issue (#15217) and a solution has been found, just need to implement it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem. question Issues that look for answers. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

6 participants