-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 fails on Windows given a space in both the command and an argument #7367
Comments
/cc @nodejs/platform-windows |
I can reproduce, working on a fix. |
I've had success using nodejs/node-v0.x-archive#25895 (comment) from the linked issue as a work around. |
Is this an issue with |
They are related, The problem is in how shell commands are executed under Windows. I have a fix almost ready, I'll publish it probably tomorrow. |
Does this not happen on v4? |
I get that. I was asking if |
@mcollina Problem exists on v4.4.4 as well. |
@s100 can you check on v4.4.7 |
LTS is affected for sure thats what I'm using. |
Im my case we are only using spawn but given its at the point of exec I assume its affected too. |
@thealphanerd still present on v4.4.7. Any others? |
Unfortunately I haven't been able to find a fix that would not also break a lot of other use cases. But there is luckily easy work around for this issue - you need to quote script filename and add
|
Thats pretty much what my fixed boiled down to, quoting the cmd Kindest Regards, Dean
|
I don't think we can do anything more with this so I'm closing the issue. You can always reopen it if you feel so. |
@bzoz Do you mean that the issue is fixed now? |
@s100 sorry, I didn't make myself clear and provide summary. My bad. The thing is, there is no way to fix this. When calling shell scripts under Windows, you need to add When the script filename has space in it, it needs to be quoted. We cannot do this automatically - FWIW I've opened a PR to add a example to the documentation: #8035 |
I just spent hours trying to figure out why electron-reloader failed to restart electron for me, and it ultimately had to do with the directory containing spaces, it trying to execute the ".cmd" executable created by npm for electron while passing it the directory (containing spaces) as an argument, and this issue popping up. Rust's standard library has an API very similar to use std::process::Command;
fn main() {
let ecode = Command::new("C:\\path with spaces\\a b.cmd")
.args(["xx yy", "1 2"])
.spawn()
.expect("failed to execute process")
.wait()
.expect("failed to wait on child");
assert!(ecode.success());
} It turns out Rust had this same problem before and solved it in rust-lang/rust#95246, by specifically handling the case where the program's filename ends with ".bat" or ".cmd" and creating a full command string involving "cmd /C ..." with the program and the arguments each escaped as necessary. It's true that child_process's docs tell users to turn on
If Node copied Rust's behavior, it would make a ton of existing programs more dependable and stop the years of people still running into this issue. This would not conflict with #29532 / #29576, because those are only about making arguments work more consistently in the |
Closes #4987 on windows, command should be quoted if containing spaces. nodejs/node#7367
Closes #4987 on windows, command should be quoted if containing spaces. nodejs/node#7367
child_process
Reproduction of the error: https://gist.github.com/smrq/f028b22bc748af9e68a7
On Windows,
child_process.spawn
handles the command incorrectly when both it and one of its arguments contains a space. So, this works fine:But this yields
'command' is not recognized as an internal or external command, operable program or batch file.
:(This is node-v0.x-archive #25895, still extant in higher Node.js versions.)
The text was updated successfully, but these errors were encountered: