1

I would like to make a batch file that writes a command to a batch file. I have tried using

@echo "@echo this is a test>test.txt">testBat.bat

Which gives me the output in testBat.bat of:

"@echo this is a test>test.txt" 

This issue is, it still has the quotations around it in the batch file, and running it without the quotes gives me:

"this is a test" 

So running it without the quotes just puts the text in the batch file. And after spending a half an hour looking I couldn't find if this was at all possible.

Nick
  • 123,192
  • 20
  • 49
  • 81
  • 1
    [Escaping characters like ", , >>, or | in the arguments to a batch file](https://stackoverflow.com/q/32414436/995714), [Batch character escaping](https://stackoverflow.com/q/6828751/995714), [Escape percent in bat file](https://stackoverflow.com/q/13551829/995714), [Escape special character in a windows batch](https://stackoverflow.com/q/32817929/995714), [Special Characters in Batch File](https://stackoverflow.com/q/37333620/995714) – phuclv Nov 18 '18 at 14:51

1 Answers1

1

Try this:

@echo @echo this is a test^>test.txt>testBat.bat

I vaguely remember that cmd uses ^ as an escape character.

melpomene
  • 81,915
  • 7
  • 76
  • 137