-
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
Quotes are not handled correctly when child_process.spawn() parses args #5060
Comments
What if you add the See Lines 332 to 333 in 4501a28
|
Good call! I changed as you recommended. And now it works: require('child_process')
.spawn('cmd', ['/s', '/c', '"node "my test/__args_out.js" b c d e f"'])
.stderr.addListener("data", data => {console.log(data.toString());}); It's required to surround the arguments list with additional quotes, too. |
@SetTrend did you mean to reopen this? |
Yes. I tested with different variations, but to no avail. I'm currently debugging into what happens when the above code is spawned. Please give me five minutes and I'll come back with a report. |
I have now run a number of tests and logged the actual process creation with SysInternals Process Monitor. Here's the result: Executing above node code, using /s switch:with surrounding quotes: .spawn('cmd', ['/s/c', '"node "test/__args_out.js" b c d e f"']) ... results in this system log:
👉 The quotes are getting escaped by node. 🔴 without surrounding quotes: .spawn('cmd', ['/s/c', 'node "test/__args_out.js" b c d e f']) ... results in this system log:
👉 The quotes are getting escaped by node. 🔴 Executing above node code, NOT using /s switch:.spawn('cmd', ['/c', '"node "test/__args_out.js" b c d e f"']) .spawn('cmd', ['/c', 'node "test/__args_out.js" b c d e f']) 👉 Same results as above. 🔴 Running directly from the command line:
results in this system log:
👉 Successful execution. 💚 Conclusion:Apparently, node erroneously escapes quotes when spawning a child process (on Windows platform). Proposed solution: node should not escape quotes when spawning a child process (on Windows platform). |
The following works for me when const command = '"node "foo bar.js" a b c"';
const child = cp.spawn('cmd', ['/s', '/c', command], {windowsVerbatimArguments: true}); |
😮 Cool. What is that option doing? It doesn't seem to be documented. Let me check here whether I'll get it going, too ... |
Thanks a lot for enlighten me on this option. It seems to work. I may be focussed here ... but before I try to amend a public project like TypeScript (or potentionally any other project on GitHub lacking this option 😉), can someone please enlighten me on this undocumented option?
|
Tells
It is silently ignored.
I'm not sure about that. Probably because it isn't needed in most cases. |
@SetTrend can this be closed? |
I'm not sure. Shouldn't this behaviour get documented for future use - for both, exec() and spawn()? |
The |
I comprehend. Will the documentation update get released then soon? What would you suggest on how to proceed? I would very much appreciate to close this issue. On the other hand I would very much appreciate to get the documentation updated final so authors can rely on this feature/option without being required to refer back to this issue. |
Closing given that there does not appear to be anything further to do (other than perhaps some better docs) /cc @nodejs/documentation |
/cc @nodejs/documentation @SetTrend Fixes nodejs#5060
Fix incorrect command and argument handling on Windows by spawning the command in a shell and by wrapping command and arguments containing spaces in quotes. See nodejs/node#5060 Fix #25 Change-Id: Ieb32892946e9a779b67b5842f4f58d18be847b0f
fails because quotes don't seem to be recognized and parsed by
child_process.spawn()
as delimiters for parameters with spaces:This happens on Windows platforms. I can't tell whether the above error occurs on other platforms, too.
The above code is taken from jake source.
The text was updated successfully, but these errors were encountered: