-
Notifications
You must be signed in to change notification settings - Fork 7.3k
child_process.spawn doc fix, args must escape spaces to get passed correctly. #4157
Conversation
Quoted strings as args do not work, you must escape the space. Example myprog -o "Long option, that takes a string". Args would be ["-o", "Long\ option,\ that\ takes\ a\ string"]
+1 |
1 similar comment
+1 |
If array is provided, arguments should be escaped automatically, this is my opinion |
I'd like to close this if possible, I described the wrong situation. I had an arg of the form -arg "String here". Using spawn's args as ["-arg","String here"] does the right thing; I was trying to use ["-arg 'String Here'] and variations on that. |
Yes, it's an array for a reason :) |
Semi-relevant, is there anything else that should be escaped within a string being passed as args as well? Double-quotes? Single-quotes? I'm seeing some odd behavior in child_process.spawn and windows and I suspect it deals with quotes. e: example of problem would be: var ps = child.spawn('wmic', ['process', 'get', 'Caption,Processid,Commandline', '/format:"C:\\code\\evening\\propercsv.xsl"']) Problem point is the /format arg - backslash escaping of the quotes used with the '/format' results in no change, and changing to single-quotes ends with a slightly different error. All errors are from wmic itself, but it seems node is butchering the args being passed along the way. This does work however: var ps = child.exec('wmic process get Caption,Processid,Commandline /format:"C:\\code\\evening\\propercsv.xsl"', function(error, stdout, stderr) {
// ... ...and it does give the right results. |
@damianb Please send support questions to the mailing list. |
@piscisaureus And documentation issues go to issue trackers. See my edit. |
@damianb Very witty, but this response was entirely reasonable given that your original post had only the first paragraph :-( |
@damianb Yes, node butchers the command line (using the conventions that the c runtime uses) to provide a reasonable emulation of the unixy "arguments array". In your case the arguments array would be translated to:
In case of wmic this apparently does not work correctly. For this we have the
|
So, windowsVerbatimArguments...isn't documented at all on the site from what I see in master. Should I open a separate issue for it then? |
Better yet, a documentation pull request. |
pr #4259 created. language could probably use improvement, open to criticism/suggested changes. |
Quoted strings as args do not work, you must escape the space. Example myprog -o "Long option, that takes a string". Args would be ["-o", "Long\ option,\ that\ takes\ a\ string"]