I want to write to txt from bat file
I write this code:
@echo off
cd C:\test_folder
set st1=cd newfolder/
set st2=mget xxxx*.csv
set st3=exit 0
echo %st1%> test2.bat
echo %st2%>>test2.bat
echo %st3%>>test2.bat
Bu the output is (test2.bat) :
cd newfolder/
mget xxxx*.csv
and the "exit" word is missed.
How can I do this?
thanks in advance
because your resulting line is
echo exit 0>>test2.bat
- where0>>test2.bat
tries to redirect the INPUT (STDIN) ofecho exit
to the file. This results in an empty output to the file and the wordecho
on the screen.echo exit 1>>test2.bat
would redirect STDOUT ("normal" output) ofecho exit
to the file (which is just the wordexit
).Even worse with
exit 2
:2
means ErrorStream, which is empty here, so your file would receive nothing at all, but STDOUT still goes to screen.Whenever your line may end in a number, better use a different syntax:
or
If you have to write several lines, you can even write all of them in one go (instead of opening the file for each file separately, write the line, close the file before opening it again for writing the next line)