How to insert multiple commands into a batch file

2019-07-18 11:24发布

I am making a batch file (Let's call it Create.bat) that will create a batch file (Let's call it Created.bat) that will get multiple commands inserted in it.

One of the commands is as follows:

FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %TEST%"') DO IF %%%x == %TEST% goto ProgramON

But when I open Created.bat to edit after running Create.bat, I see the following code inserted:

FOR /F %%x == %TEST% goto ProgramON

Why does it cut out a portion of the code, and how can I fix it?

1条回答
2楼-- · 2019-07-18 11:51

Some characters have to be escaped. Most of them (&<>|) with a caret (^). Percent signs are escaped with another percent sign:

>>created.bat echo DIR ^>nul
>>created.bat echo FOR /F %%%%x IN ('tasklist /NH /FI "IMAGENAME eq %%TEST%%"') DO IF %%%%x == %%TEST%% goto ProgramON
查看更多
登录 后发表回答