0

How to write to a batch file a command which itself writes to another file. Basically what I'm trying to achieve is this

File1.bat
echo abc >> op.txt

File2.bat
echo abc >> op.txt >> main.txt

I'd like to following statement to be the content of main.txt when I run File2.bat but that didn't happen

main.txt
echo abc >>op.txt

2 Answers 2

2

In order to echo the > character, you need to escape it with ^.

If the contents of File2.bat are:

echo echo abc ^>^> op.txt >> main.txt

then after running File2.bat, the contents of main.txt will be:

echo abc >> op.txt

Read more about escape characters.

1

Im not sure at 100% if it will work but I think what you have to do is:

echo (

Your Code

) > Directory\Batchfile.bat
1
  • Welcome to SuperUser! When posting an answer please make sure it works. This time we checked it for you and it doesn't work. Please edit and make it a working answer, otherwise it will get removed
    – Jet
    May 16, 2015 at 22:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .