如何批量写入命令?

时间:2013-07-01 20:44:17

标签: batch-file

在批处理中,有没有办法编写命令来运行文件?

例如我的脚本是:

ping 127.0.0.1 >> file.txt

我想将ping 127.0.0.1包含到我的file.txt中,这样我就知道哪个命令产生了哪个输出。

当然我可以这样做:

echo "ping 127.0.0.1" >> file.txt
ping 127.0.0.1 >> file.txt

2 个答案:

答案 0 :(得分:4)

调用批处理脚本时,请保留echo on并输出整个脚本。

命令行

script.bat >> file.txt

Script.bat

@echo on
ping "127.0.0.1"

这也可以由脚本用

自行调用
@echo off
if /i not "%~1"=="self" call "%~f0" self >> file.txt & goto :EOF
@echo on
:: Everything (including commands) after this echo will be displayed in the file
ping "127.0.0.1"

答案 1 :(得分:0)

怎么样

@echo on

在一个命令块之前,你想要记录,并且

@echo off
之后呢?

@echo off
rem what i want to do
rem some commands (setting variables etc.)
@echo on
ping 127.0.0.1" >> file.txt
ipconfig /all >>file.txt
@echo off
rem some other commands (deleting temporary files etc)