Answer the question
In order to leave comments, you need to log in
Why do command line options break if they end with a slash?
I came across a very interesting case, in my opinion this is a bug in its purest form, but very rare and difficult to detect.
The main point is that the program/script is called with the passing of parameters containing spaces enclosed in double quotes. At the same time, if the parameter contains a trailing slash (in windows style!), then a failure occurs when parsing parameters at the level of ruby/php interpreters, or maybe binaries have the same problem?!
php script.php "param1 with space and leading slash\" "param2 with space too"
ruby script.rb "param1 with space and leading slash\" "param2 with space too"
C:\cmd_line_test>
cmd_line_test.exe "param1 with space and leading slash\" "param2 with space too"
argc=5
argv[0]=|C:\cmd_line_test\cmd_line_test.exe|
argv[1]=|param1 with space and leading slash" param2|
argv[2]=|with|
argv[3]=|space|
argv[4]=|too|
param1 with space and leading slash\"should be the first argument, if we take into account the escape rule
\"?!
Answer the question
In order to leave comments, you need to log in
trailing slash (windows-style!)
because for that matter, it is the line
param1 with space and leading slash\"
that should be the first argument, if we take into account the escape rule as well
test.cmd:
@echo %1
@echo %2
test.cmd "param1 with space and leading slash\" "param2 with space too"
"param1 with space and leading slash\"
"param2 with space too"
program ... glitchesThere are no errors with the program either:
program Project1;
{$APPTYPE CONSOLE}
uses System.SysUtils;
var i: Integer;
begin
for i := 0 to ParamCount do Writeln( ParamStr(i) ); // uses GetCommandLineW
end.
Project1.exe "param1 with space and leading slash\" "param2 with space too"
Project1.exe
param1 with space and leading slash\
param2 with space too
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question