pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

Problem starting GUI apps under Windows with Node 8.x

Open natcl opened this issue 8 years ago • 12 comments

Using NodeJS 6.x I can easily start a GUI app with pm2:

pm2 start notepad.exe

The window will stick.

With NodeJS 8.x running the same command seems to hide the notepad window even though it still shows in PM2's process list. Is this a bug with Node 8.x ? Thanks !

natcl avatar Jan 24 '18 16:01 natcl

Could this be related to the fact pm2 tries to hide windows now ? Would there be a way to bypass that ?

natcl avatar Jan 25 '18 15:01 natcl

IMO it's a feature \o/

Could this be related to the fact pm2 tries to hide windows now ?

exactly my thought as well

Would there be a way to bypass that ?

Not currently! A PR adding that possibility would be nice IMO!

Just for my information, why do you need to run notepad from pm2 :laughing:

soyuka avatar Jan 25 '18 16:01 soyuka

Notepad was just an easy example but we usually use PM2 as a watchdog for multimedia frontend apps. Works quite well for this except when the windows disapear...

natcl avatar Jan 25 '18 19:01 natcl

I'm not familiar with the codebase but could dig into it, any tips on how you would like to see implemented ? I assume it would be an option in the process file ?

natcl avatar Jan 25 '18 20:01 natcl

I'm not familiar with the codebase but could dig into it, any tips on how you would like to see implemented ? I assume it would be an option in the process file ?

Yes. I think it's due to the changes:

  • https://github.com/Unitech/pm2/commit/28d28b4995863b372112de7fa018b328c14b3582
  • #3400 (not merged yet)

soyuka avatar Jan 26 '18 09:01 soyuka

Thanks will dig in and submit a PR

natcl avatar Jan 29 '18 19:01 natcl

Would declaring this in the env of the process be sufficient, like this ? Or would you rather have it as a normal pm2 option on the top level of the apps definition ?

{
	"apps": [{
		"name": "notepad",
		"script": "notepad.exe",
		"watch": true,
		"env": {
			"windowsHide": false
		}
	}]
}

natcl avatar Feb 13 '18 15:02 natcl

With this in ForkMode.js:

      var windowsHide = true;
      if (pm2_env.windowsHide != undefined) {
        windowsHide = pm2_env.windowsHide;
      }
      try {
        var cspr = spawn(command, args, {
          env      : pm2_env,
          detached : true,
          windowsHide: windowsHide,
          cwd      : pm2_env.pm_cwd || process.cwd(),
          stdio    : ['pipe', 'pipe', 'pipe', 'ipc'] //Same as fork() in node core
        });
      }

natcl avatar Feb 13 '18 15:02 natcl

Although it seems much cleaner to add it to schema.json:

  "windowsHide": {
    "type": "boolean",
    "default": true
  }

natcl avatar Feb 13 '18 16:02 natcl

Hi,

I have a .js file with this command:

exec("D:\test.vbs", {windowsHide:true}, function(error, stdout, stderr) {

In test.vbs I only have:

MsgBox "Hello World"

If I run my program with node index.js, the box correctly appears, alone. But if I use pm2 then the message box appears, but also a black CMD.exe window in the background too.

capture

I'm not sure if I'm doing it wrong, if I should change a variable somewhere, or a config file somewhere? I think this thread is related to my issue... Help would be appreciate.

Thanks

Aymkdn avatar Apr 03 '18 10:04 Aymkdn

Nevermind. I've just updated Node to v9.10.1 et pm2 to 2.10.2 and it now works :-)

Aymkdn avatar Apr 03 '18 11:04 Aymkdn

this is great and super useful. it also appears to be missing from the docs

gschomburg avatar Sep 28 '21 12:09 gschomburg