在批处理中,有没有办法编写命令来运行文件?
例如我的脚本是:
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
答案 0 :(得分:4)
调用批处理脚本时,请保留echo on
并输出整个脚本。
script.bat >> file.txt
@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)