2

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?

2
  • How are you inserting the commands into created.bat? Commented Sep 3, 2017 at 16:19
  • Using: echo COMMAND >> Created.bat Commented Sep 3, 2017 at 16:52

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments