Problem starting GUI apps under Windows with Node 8.x
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 !
Could this be related to the fact pm2 tries to hide windows now ? Would there be a way to bypass that ?
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:
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...
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 ?
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)
Thanks will dig in and submit a PR
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
}
}]
}
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
});
}
Although it seems much cleaner to add it to schema.json:
"windowsHide": {
"type": "boolean",
"default": true
}
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.
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
Nevermind. I've just updated Node to v9.10.1 et pm2 to 2.10.2 and it now works :-)
this is great and super useful. it also appears to be missing from the docs