I'm trying to understand how the ^ Caret escape works in a Batch CMD. Lets say I type this line in a CMD Window, I would expect it to send the DIR listing to "c:\my text.txt"
CMD.EXE "/C > ^"c:\my text.txt^" DIR C:\*.*"
Instead I get the error:
'txt.txt" DIR *.*"' is not recognized as an internal or external command,
operable program or batch file.
If I do something as simple as this:
ECHO "^"^""
Expected: """"
Actual : "^"""
Even if I try double quoting like this:
ECHO " "" "" "
Expected: " " " "
Actual : " "" "" "
Can someone 'splain how this works and what is a reliable way is to escape double quotes in a command line?
Thanks.
Additional Example:
Why does this work:
cmd.exe "/C sqlcmd.exe -S.\SQLEXPRESS -E -Q"select suser_name()" > "c:\temp\test 1.txt""
but this gives error "The system cannot find the path specified." and does not create the txt file.
cmd.exe "/C "sqlcmd.exe" -S.\SQLEXPRESS -E -Q"select suser_name()" > "c:\temp\test 1.txt""
I know it is not needed in this case, but how would I enclose the command sqlcmd.exe in quotes?
I also tried removing the quotes from the whole line with the same results, i.e.,
cmd.exe /C "sqlcmd.exe" -S.\SQLEXPRESS -E -Q"select suser_name()" > "c:\temp\test 1.txt"
Thanks again.