-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
child_process.spawn() requires "/" but path.resolve() returns "\" on windows #3116
Comments
What error does it produce? |
oh man, i didn't document the error, but if I recall, spawn() tried to digest the path up to the first "" and dropped the rest which resulted in a path not found or similar |
I'm investigating a very similar case where spawn throws E.i: t1.js
t2.js
path.normalize does not make any difference. This is a Windows only issue which makes me think that |
After reading the an old issue in node 0.6 I figure that the shebang I use saved me on mac and linux but became an issue on windows. The work around for Windows's missing shebang support is add path as a arguments to nodejs.
|
@dotnetCarpenter if you use the latest code from master, you can do: 'use strict';
const cp = require('child_process');
const file = require.resolve('./foo');
const child = cp.spawn(file, {shell: true});
child.stdout.setEncoding('utf8');
child.stdout.on('data', console.log); I tested this on Windows 7 and OS X. Node handles the shebang for you on all platforms. The only catch is that on Windows, the |
@cjihrig well, that gotcha makes nodejs code unportable. 'use strict';
const cp = require('child_process');
const file = require.resolve('./foo');
const child = cp.spawn(file, {nodejs: true}); // tell child_process this is a nodejs executable
child.stdout.setEncoding('utf8');
child.stdout.on('data', console.log); Please reopen. |
@dotnetCarpenter |
@bnoordhuis You're completly right. I somehow forgot that. |
ERRORS:
var mypath = path.resolve('node_modules', 'package', 'scriptName.cmd');
var cp = child_process.spawn(mypath, args);
WORKS:
var mypath = path.resolve('node_modules', 'package', 'scriptName.cmd');
mypath = mypath.replace(//g, '/');
var cp = child_process.spawn(mypath, args);
The text was updated successfully, but these errors were encountered: