[英]How can I write “exit” word to txt from bat file?
I want to write to txt from bat file 我想从bat文件写入txt
@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
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
- where 0>>test2.bat
tries to redirect the INPUT (STDIN) of echo exit
to the file. 因为您得到的行是
echo exit 0>>test2.bat
其中0>>test2.bat
尝试将echo exit
的INPUT(STDIN)重定向到文件。 This results in an empty output to the file and the word echo
on the screen. 这将导致文件输出为空,屏幕上将显示单词
echo
。
echo exit 1>>test2.bat
would redirect STDOUT ("normal" output) of echo exit
to the file (which is just the word exit
). echo exit 1>>test2.bat
将重定向STDOUT的(“正常”输出) echo exit
到该文件(这仅仅是字exit
)。
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. 更糟糕的是,
exit 2
: 2
表示ErrorStream,此处为空,因此您的文件将什么都收不到,但是STDOUT仍然显示在屏幕上。
Whenever your line may end in a number, better use a different syntax: 每当您的行以数字结尾时,最好使用其他语法:
>>test2.bat echo exit 0
or 要么
(echo exit 0)>>test2.bat
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) 如果您必须写几行,甚至可以一次写完所有行(而不是分别为每个文件打开文件,而是写一行,在再次打开以写下一行之前关闭文件)
>test2.bat (
echo %st1%
echo %st2%
echo %st3%
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.