rannn505 / child-shell

Node.js bindings 🔗 for shell
http://rannn505.github.io/child-shell/
MIT License
301 stars 71 forks source link

Powershell crash when running in Windows Server 2012 R2 #98

Closed davistran86 closed 5 years ago

davistran86 commented 5 years ago

Everything is running fine on Windows 10 but when I moved it to Windows Server 2012 R2 for production then it crashed every time I run it.

I tried with the example from this repo as well, but it still crash. It seems cannot spawn the shell.

I'm running node 10.16.x on Windows Server 2012 R2

davistran86 commented 5 years ago

If I run 'powershell -NoLogo' in powershell then run the script again then it works. Something wrong with the shell when it is spawned ?

davistran86 commented 5 years ago

I think the error when the shell is spawned is:

'-' was specified as the argument to -Command but standard input has not been redirected for this process.

With manually running powershell -Nologo, I can start the script with node or nodemon OK but if I use pm2 it's still error as pm2 spawn new window

davistran86 commented 5 years ago

I fixed it.

In Shell.js change

    const proc = spawn(`${psProc}${!isWin ? "" : ".exe"}`, psOpts, {
      stdio: "pipe"
    });

To

    const proc = spawn(`${psProc}${!isWin ? "" : ".exe"}`, psOpts, {
      stdio: "pipe",
      shell: isWin,
      windowsHide: isWin
    });