2

批量,有没有办法将命令写入文件?

例如我的脚本是:

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
4

2 回答 2

4

调用批处理脚本时,离开echo on并输出整个脚本。

命令行

script.bat >> file.txt

脚本.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"
于 2013-07-01T21:09:18.480 回答
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) 
于 2013-07-01T21:09:24.557 回答