问题
I need to execute an .exe file (with two different arguments in parallel). The execution of the EXE file works like this:
C:\WorkDir> "C:\ProgramFiles\MyProgram\my.exe" "XML_PARAMETER_STRING"
I need to pass the XML_PARAMETER_STRING to this program from command line, which contains some special characters, like " ' < >
e.g.:
<WizardValues> <Module>D:\some path\calc.yxwz</Module> <Value name='param1'>True</Value> <Value name='param2'>2019-09</Value> </WizardValues>
The program execution from command line works properly if I do this:
C:\WorkDir> "C:\ProgramFiles\MyProgram\my.exe" "<WizardValues> <Module>"D:\some path\calc.yxwz"</Module> <Value name='param1'>True</Value> <Value name="param2">2019-08</Value> </WizardValues>"
... but it fails when I try something like this (to run them parallelly see the sidenote below):
escaping every special character:
cmd /C " ^"C:\Program Files\MyProgram\my.exe^" ^"^<WizardValues^> ^<Module^>^"D:\some path\calc.yxwz^"^</Module^> ^<Value name='param1'^>True^</Value^> ^<Value name='param2'^>2019-08^</Value^> ^</WizardValues^>^" > output.txt"
give as multiple arguments:
cmd /C "C:\Program Files\MyProgram\my.exe" "<WizardValues> <Module>"D:\some path\calc.yxwz"</Module> <Value name='param1'>True</Value> <Value name='param2'>2019-08</Value> </WizardValues>" > output.txt
(I've read that the escape character in windows command line is ^
, but it does not seem to work as expected). I get errors like this:
< was unexpected at this time.
or
'"D:\Program' is not recognized as an internal or external command, operable program or batch file.
Questions:
- What am I donig wrong?
- How could I execute both commands parallelly from command line?
- What is wrong in my solution?
Sidenote:
I need to start two processes from command line, each should run in parallel. There is a need to wait until both process finishes.
The following bat file solves this problem (I'm trying to create a solution based on this, that's why I need a solution with cmd /C "COMMAND"
):
(
start "task1" cmd /C "timeout /t 5 /nobreak > nul"
start "task2" cmd /C "timeout /t 3 /nobreak > nul"
) | pause
来源:https://stackoverflow.com/questions/57887232/how-to-escape-special-characters-in-windows-command-line