When running a program via Comspec (cmd.exe) ... if the path or name of the executable contains spaces, the entire string should be enclosed in an outer pair of single-quote marks.
Code: Select all
Run A_ComSpec ' /c "C:\My Utility.exe" "param 1" "second param" >"C:\My File.txt"'
I first tried this pattern.
Code: Select all
App := "C:\My Utility.exe"
Text := "C:\My File.txt"
Run A_ComSpec ' /c "' App '" "param 1" "second param" > "' Text '"'
To fix the error we can add an extra double-quote after /c and before the last single-quote.
Run A_ComSpec ' /c " "' App '" "param 1" "second param" > "' Text '" " '
Why are those extra double-quotes needed? Is it a bug? Incomplete/incorrect documentation? neogna2 comprehension problem?
Follow these steps to reproduce the issue. I use Handle only as an example here, the pattern is the same also with other apps as long as there are spaces in the app's path or filename.
- Download Handle from Microsoft's SysInternals, https://download.sysinternals.com/files/Handle.zip (800kB)
- Create the folder C:\a b\ and copy handle64.exe into that folder
- Save the below v2 scripts as C:\a b\test.ahk
- Open one more File Explorer window and navigate to C:\ , which Handle should find if all goes well.
- Run the script with AutoHotkey v2 beta 3
Code: Select all
;test 1 (error)
Command := "C:\a b\handle64.exe"
Path := "C:"
RunWait A_ComSpec ' /k "' Command '" -p Explorer.exe "' Path '" '
; using /k instead of /c to persist cmd window with error text until manually closed
;test 2 (no error, notice the extra double-quotes)
RunWait A_ComSpec ' /k " "' Command '" -p Explorer.exe "' Path '" " '