!system `"%WINDIR%\notepad.exe" "c:\windows\temp\x.txt"`
will not work (NSIS 2.17).
It seems that !system cannot cope with more than one
quoted parameter in the commandline when the command
starts quoted...
workaround:
!system `if 1==1 "%WINDIR%\notepad.exe"
"c:\windows\temp\x.txt"`
Logged In: YES
user_id=584402
That's a limitation of Windows' command line processor. If
the first part is quoted, it ignores the second set of
quotes. You can use !execute to work around the command line
processor. To get %WINDIR% without it, use $%WINDIR%. If I
recall correctly, Raymond Chen blogged something about this
a couple of months ago. cmd.exe /? should also spill some
more details on the topic, especially the /S switch.
Logged In: YES
user_id=1216614
Thanks for the reply. You should mention that in NSIS' help,
because the first example for the !system-instruction will
reveal this 'limitation' ;)
Perhaps you could put in my workaround too...
Logged In: YES
user_id=1216614
And, by the way: "%WINDIR%\notepad.exe"
"c:\windows\temp\x.txt" works as expected when you type it
into a console window. So where is the limitation ?
Logged In: YES
user_id=584402
The limitation is in the way system() calls cmd.exe. It
executes the following command, where %1 is what it got as
an argument:
cmd.exe /C %1
If there is more than one set of quotes and the first and
last characters are quotes, it removes the outer quotes. I
still have a good idea as to why...
Possible solutions include using CreateProcess with the
correct output and input handles to mimic system's behavior.
This, however, makes it impossible to use the feature of the
command line processor, such as redirection and batch
scripting. Another solution is parsing the string and
converting the executable path into a short file name,
without any quotes. But this is a bit complicated.
Last solution is your solution of adding a harmless prefix
to the command. I tried adding `@`, which is shorter, but it
didn't work on older Windows versions. I added your solution
as it worked on all versions of Windows. I'm a bit uneasy
about changing the command line, but tests pass and it seems
safe enough. Hopefully there won't be any side effects.
!packhdr, which was also affected, is now using the new
sane_system() function as well.