Reputation: 35
I want to write a command like this inside a file using only cmd.exe (with ShellExecute, C++),
It's something like this:
timeout /t 10 && start cmd.exe /C "ssh -o ..."
I tried using this:
echo timeout /t 10 && start cmd.exe /C "ssh -o ..." > myfile.bat
but it cuts when it reaches &&
and I can't use quotes on the entire string, so what should I do? I don't want to use anything other than cmd.exe, and I just want to write this to a .bat
file.
How can I solve this?
Upvotes: 1
Views: 114
Reputation: 82202
1) Use disappearing quotes.
FOR %%^" in ("") do (
echo %%~"timeout /t 10 && start cmd.exe /C "ssh -o ..." %%~" > myfile.bat
)
2) Escape the special characters
echo timeout /t 10 ^&^& start cmd.exe /C "ssh -o ..." > myfile.bat
3) Use delayed expansion
setlocal EnableDelayedExpansion
set "line=timeout /t 10 && start cmd.exe /C "ssh -o ...""
echo !line! > myFile
Upvotes: 3