Reputation: 5651
In batch, is there a way to write the command to run into a file?
For example my script is:
ping 127.0.0.1 >> file.txt
I want to include ping 127.0.0.1
into my file.txt so I would know which command produced which output.
Of course I could simply do:
echo "ping 127.0.0.1" >> file.txt
ping 127.0.0.1 >> file.txt
Upvotes: 2
Views: 752
Reputation: 11367
When calling the batch script, leave echo on
and output the entire script.
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"
Upvotes: 4
Reputation: 56180
How about
@echo on
before a block of commands, you want to log, and an
@echo off
after that?
@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)
Upvotes: 0