-
Notifications
You must be signed in to change notification settings - Fork 53
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
Use spawn
rather than exec
to support paths with spaces
#539
Conversation
exec(command, (error, stdout, _) => { | ||
if (error) { | ||
reject(error); | ||
const child = spawn(cmd, args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think execFile is what we want here https://nodejs.org/api/child_process.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that looks better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change.
I was about to file an issue for that, thanks! Although I’m mystified why “slap a string together and execute it as a shell script” is still a thing people occasionally do. Sorry for the harshness in the preceding sentence, I appreciate all the hard work! |
Our use-case is to find out the |
What I’m saying is that there’s a reasonable API to call a binary with optional arguments This PR switched from the latter to the former, for which I’m grateful, but I’m puzzled why anyone would ever default to the latter way. |
## Summary I use ruff for our embedded python interpreter. This interpreter needs to be bootstrapped (env-vars) before be able to get called (technical limit of the environment itself). This is usually done with `.cmd` file (the modern version of `.bat`) on windows which is kind of similar to `.sh` on linux. `.cmd` files are often use on Windows, even vscode itself use it to start vscode on windows. Today I noticed that I get a crash when using the `.cmd` interpreter path. It seems that node require shell mode (in windows calling `cmd.exe` as the shell) to be able to call `.cmd` files correctly. I needed to quote the input filename as well to avoid whitespace issues which looks like a bug in node itself. With that PR I got no crashes anymore when the extension try to run ruff 😄 . Note: The shell mode only get activated when the platform is windows and the file extension is `.cmd`, so users with regular executables should not be affected at all. ## Test Plan Manual testing it locally works great and as expected. I added a utils-test to check the require shell mode flag. The PR is related to the changes of #539 --------- Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Summary
If the interpreter path contains a space, then the find script fails. We need to escape the arguments that we pass to
exec
. But, it seems easier to just usespawn
, which doesn't require escaping.Closes astral-sh/ruff#12394.
Test Plan
Created a virtual environment
foo bar
in a repo; verified that the script failed before but succeeds after this change.