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

Error running forever.js on Windows - “'C:\Program' is not recognized as an internal or external command, operable program or batch file” #1056

Open
sambragg opened this issue Jan 13, 2020 · 16 comments

Comments

@sambragg
Copy link

I am trying to run forever.js via the Windows command prompt and I get the following output:

>npm i -g forever

/my-project>forever start index.js

Log output:

'C:\Program' is not recognized as an internal or external command, operable program or batch file

I think it's something to do with the PATH that forever is using for the node binary, but I don't know how to fix it...

Link to my question on Stack Overflow

@MrDj200
Copy link

MrDj200 commented Jan 25, 2020

I've got the same problem.
My best guess its the space in the path

@sunk818
Copy link

sunk818 commented Jan 25, 2020

@sambragg If you type dir /x in the root of c:, you can see the short name of the directory.

So, try the following instead:

C:\PROGRA~1\nodejs\node.exe

dir /x example

@sambragg
Copy link
Author

@sunk818 thanks for your reply on this issue and on SO. I understand the issue now thanks to your explanation but how do I tell forever to use this new path that you have suggested?

@sunk818
Copy link

sunk818 commented Jan 28, 2020

@sambragg I've never run node npm on Windows so I don't know from personal experience.

https://stackoverflow.com/questions/27864040/fixing-npm-path-in-windows-8-and-10

if you run set from the command prompt, one of the entries might be for nodejs. Then you can try editing the path with the short name. User environmental variables may require you to reboot your system (or at least log out). System environment variables should apply immediately to the next command prompt you open.

The other brute force way is run Process Monitor from sysinternals , filter on process name containing forever , and see how the software traverses through finding npm. I think getting stuff like this to run in Windows is painful. At least consider running on Ubuntu WSL (Windows for Subsystem Linux) in the future and see if you get better results.

@smt9020
Copy link

smt9020 commented Feb 10, 2020

I am having this same problem. If you install version 1.0.0 it works.

@eskim0223
Copy link

Yes,installing version 1.0.0 also worked for me

@kibertoad
Copy link
Contributor

I've just added a test that tries replicating this issue: #1068
It works fine both locally (Windows 10) and in CI.
If someone could provide a reliable repro for the problem, that would be fantastic.

That said, I'm pretty sure problem is caused by foreversd/forever-monitor#145, but would be great if I could have a reproduction to confirm before doing any changes, that hiding that change behind an option would indeed help.

@davecarlile
Copy link

Windows 10:

npm install forever-monitor

hello.js:
console.log('hello world')

index.js:
var forever = require('forever-monitor');
var child = new (forever.Monitor)('hello.js', {
max: 3,
silent: false,
args: []
});

child.on('exit', function () {
console.log('hello.js has exited after 3 restarts');
});

child.start();

node index

result:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
your-filename.js has exited after 3 restarts

Is there a workaround for this? Can I explicitly point to the node binary?

@sasodoma
Copy link

sasodoma commented Mar 20, 2020

What worked for me, since node.exe is in my path, i just used forever start -c node app.js and it started correctly. The other way is to change your system nodejs path to the short name (PROGRA~1)

@foodbandlt
Copy link

@sasodoma I got to this same conclusion before finding this thread. I ran into a problem doing it that way though, would you mind checking if you have the same problem?

Once I started the daemon using -c node, when I used forever stopall, it failed to kill the child process for the script. So forever list says nothing is running, but the process for the script is still running in the background.

I ended up downgrading as mentioned above to 1.0.1, but I'm curious if this was something others had issues with too.

@sasodoma
Copy link

@foodbandlt Yes I had the exact same problem. My app was running and express server and socket.io. Running stopall didn't kill it and I also couldn't restart it because it wouldn't kill the old one and the the ports would clash.

Also note that I don't think this is a problem with the -c option since I have tried the other way (using a short name in the PATH) and it still couldn't kill the process.

@yosiasz
Copy link

yosiasz commented Apr 17, 2020

The way it worked for me, in Windows, was to choose a folder to install to that does not contain a space. So Installed node to c:\ProgramFiles instead of c:\Program Files => { Works! }

@ghost
Copy link

ghost commented Apr 26, 2020

Why not just enclose the path in quotes?
process.execPath = '"' + path.normalize(process.execPath) + '"';

@TuomoKu
Copy link

TuomoKu commented Apr 27, 2020

I'm having the same issue C:\Program' is not recognized as an internal or external command.. when trying to use forever (v1.0.0) in npm start script. The issue appears on my client's Win10 PC but not on my development Win10 PCs. Env path of Node is changed to short name PROGRA~1which helps with node but not with forever.

@kibertoad
Copy link
Contributor

Can you try forever 3.0.0?

@Didier68
Copy link

Didier68 commented Jul 8, 2021

Hi, I have the same issue with forever 2.0.0 on a Windows 10 PC... and I cannot upgrade "forever" because of an " No matching version found for forever-monitor@^4.0.1." error...

My workaround (in the "forever.js" file):

`

const configChild = {
    //
    // Basic configuration options
    //
    silent: true,     // Silences the output from stdout and stderr in the parent process
    'killTree': true, // Kills the entire child process tree on `exit`
	....
}

// =======================================================
// **Workaround for Windows** 
// =======================================================
if (process.platform === 'win32' && process.execPath == "C:\\Program Files\\nodejs\\node.exe") {
    configChild.command = '"C:\\PROGRA~1\\nodejs\\node.exe"';
}

const child = new (forever.Monitor)('app.js', configChild);

....

child.start();

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests