China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-28 17:59
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How can the console automatically record all input commands and output them to a file? View 2,079 Replies 5
Original Poster Posted 2005-12-02 17:42 ·  中国 北京 鹏博士BGP
新手上路
Credits 18
Posts 5
Joined 2005-11-30 14:07
20-year member
UID 46224
Status Offline
If I open a console, no matter what operations I have done in it, I hope to track the operation records and finally write them into a file. For example, I have done the following operations in the console:

C:\>set value=1

C:\>Change_Value.bat

C:\>echo 1
1

C:\>set value=2

C:\>echo 2
2

C:\>set value=3

C:\>%value%
'3' is not an internal or external command, nor is it a runnable program
or batch file.

C:\>

Then when I exit the console, I want to save all the run commands above in a file, say Command.log. The content recorded in the file is, for example:
set value=1
Change_Value.bat
echo 1
set value=2
echo 2
set value=3
%value%

Is there any good way? The way we are doing now is to write an echo under each command, and then repeat the command above and write it after the echo. This way is very stupid and easy to make mistakes. Please give me some advice, great experts!
Floor 2 Posted 2005-12-02 22:48 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
Press F7, then copy these commands.
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 3 Posted 2005-12-05 09:34 ·  中国 北京 鹏博士BGP
新手上路
Credits 18
Posts 5
Joined 2005-11-30 14:07
20-year member
UID 46224
Status Offline
This still doesn't achieve my purpose! I want to make a bat file, and I want to output all the executed commands after the bat file is executed. But when I put doskey /h at the last line of the bat file, there is nothing output. It seems that the commands in the bat file are not recorded at all. I'm苦恼! Do you guys have any other ways?
Floor 4 Posted 2005-12-05 13:48 ·  中国 山西 太原 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re tuliplanet:

A very interesting topic. According to your requirements, I wrote the following BatDump code. It can only dump some simple batch scripts. When encountering some complex batch scripts, there will be many unexpected problems, after all, it is not the normal execution process of a program. In addition, if the batch script to be dumped contains statements like pause that need to accept keyboard input, the selection confirmation needs to be done "in the dark" during the dumping process (the situation in CMD is relatively special).


:: BatDump.bat - V2 - Dump process of batch program
:: Will Sort - 2005-12-06 - CMD@WinXP/MSDOS7.10/MSDOS6.22
@echo off
if not "%1"=="" if exist %1.bat goto Dump

:Usage
echo.
echo BatDump - Dump process of batch program
echo Usage: %0 batname(without extname)
echo Sample: %0 test
echo.
goto end

ump
ren %1.bat %1.bak
echo @echo off>%1.bat
echo set prompt=# >>%1.bat
echo echo on>> %1.bat
find /v "echo off" < %1.bak >> %1.bat
shift
%comspec% /c %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 | find "#"
if exist %0.bat del %0.bat
ren %0.bak %0.bat

:end
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 5 Posted 2005-12-05 16:45 ·  中国 北京 鹏博士BGP
新手上路
Credits 18
Posts 5
Joined 2005-11-30 14:07
20-year member
UID 46224
Status Offline
Hmm~~! The Great Expert's meaning is that you copied all the commands in the bat file into one file, but what we need is to really know which commands were run when the bat file was executed. For example, there are if else statements and goto statements when running, and some branches are not taken. We need to record the running state of the bat, not what's in it. So, experts, see if there are other good ways?
Floor 6 Posted 2005-12-05 18:30 ·  中国 山西 临汾 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re tuliplanet:

I don't know how you tested my code? Its function is exactly to obtain a sequence of running statements of a batch file, so the text intercepted by it is no longer a strictly batch file. For example, there will only be goto label in this text, and there will be no :label label.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: