-
Notifications
You must be signed in to change notification settings - Fork 31.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.exec() fails with spaces in absolute or relative path to binary file #6803
Comments
If the same binary is passed as a relative path, e.g. just |
Yep, quick test locally confirms this. As a workaround, if you wrap the command in quotes it should work, e.g.: child_process.exec('"/path/to/test script.sh"', (err, stdout, stderr) => { }); Looks like we need to make sure we're wrapping it in quotes internally if is isn't wrapped already. |
Care to make a PR? :-) |
Sure. I would like to understand a bit more about why I tried tracing the |
@jorangreef I did some digging for you
If the
The It would appear that the path handling at that point is happening at the libuv layer. We could likely do some prints from the c++ layer to verify, but I'm 99% that we are just passing the filepath as given as long as the |
Thanks @thealphanerd! I see that the
This means that the
This is eventually executed on Linux and OS X by
So
And
Therein lies the problem, |
It looks like Windows is also affected. I have also found the reason why my earlier Should I am sure there are users who are already passing a fully quoted or partially quoted/escaped I would like to make this change as safe and backward compatible as possible. I think what would work best is if we escape any special character which is not yet already quoted or escaped, as follows:
These should all then work when they end up being called. For example:
Should the escaping be done in the
What have I missed? Are there any other edge cases to consider? What should we consider to be quote-worthy special characters on Windows and on Linux and OS X? Anything that's not in These changes should hopefully not break anything, but if you want me to proceed then I think they should still best be landed only in the next semver major. It would be good also to get some more eyes on this. |
Could we pass the command to |
Not escaping spaces is the expected behavior. If exec() started escaping, then e.g. Not a bug, IMO, although the documentation for exec() can probably be more explicit; "executes the |
@bnoordhuis ... good point. That would imply that the right solution here is to expand the documentation to address the fact that paths with spaces need to be quoted before passing in. |
@bnoordhuis Thanks, I came across this via What about |
No, it's passed verbatim as the
|
Okay, great. Sorry for the confusion. |
Thanks for the clarification @bnoordhuis ! |
Updates the Child Process Exec function documentation providing further information with regards to treating special characters in the command string function argument. Note that the exec string is processed by the shell. Updates description to show that special shell characters vary based on the shell with a link to the Wikipedia page regarding different command line interpreters and their associated operating systems. Updates example code to reside in separate lines using a codeblock and utilizes examples to comply with code standards by using single quotes. Fixes: nodejs#6803
…s in the path. See: nodejs/node#6803 Fixes: brave#8516
…s in the path. See: nodejs/node#6803 Fixes: brave#8516
We found that we where not able to install `detox` if the project is installed on a path with spaces on parent directories. For example, if we clone the project on `~/My Projects/my-project`, running `npm install` will fail to locate the `detox/scripts/build_framework.ios.sh`. ``` /bin/sh: /Users/me/My: No such file or directory child_process.js:615 throw err; ^ Error: Command failed: /Users/me/My Projects/my-project/node_modules/detox/scripts/build_framework.ios.sh at checkExecSyncError (child_process.js:575:11) ``` This is related to [node's child_process](nodejs/node#6803) handling of filepaths on `exec`. Instead of locating the file as `~/My Projects/my-project/node_modules/detox/scripts/build_framework.ios.sh`, it passes the argument as `~/My` and fails to execute. This commit changes the execution process to threat the first argument as a file path, instead of arguments to `exec`, which triggers the split by space to determine the arguments. Co-Authored-By: Fellipe Chagas <[email protected]> Co-Authored-By: Rafael Correia <[email protected]>
We found that we where not able to install `detox` if the project is installed on a path with spaces on parent directories. For example, if we clone the project on `~/My Projects/my-project`, running `npm install` will fail to locate the `detox/scripts/build_framework.ios.sh`. ``` /bin/sh: /Users/me/My: No such file or directory child_process.js:615 throw err; ^ Error: Command failed: /Users/me/My Projects/my-project/node_modules/detox/scripts/build_framework.ios.sh at checkExecSyncError (child_process.js:575:11) ``` This is related to [node's child_process](nodejs/node#6803) handling of filepaths on `exec`. Instead of locating the file as `~/My Projects/my-project/node_modules/detox/scripts/build_framework.ios.sh`, it passes the argument as `~/My` and fails to execute. This commit changes the execution process to threat the first argument as a file path, instead of arguments to `exec`, which triggers the split by space to determine the arguments. Co-Authored-By: Fellipe Chagas <[email protected]> Co-Authored-By: Rafael Correia <[email protected]>
Using exec() to execute an absolute path to a binary, with spaces in the absolute path, e.g.
/Users/Joran/test script.sh
fails:The text was updated successfully, but these errors were encountered: