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-08-01 00:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to print DOS error messages to a txt file? View 6,477 Replies 18
Original Poster Posted 2004-03-04 00:00 ·  中国 北京 鹏博士BGP
初级用户
Credits 104
Posts 1
Joined 2004-03-04 00:00
22-year member
UID 19129
Gender Male
Status Offline
For example, I run a self-written program whose content is to COPY a file from one directory to another. When the file does not exist, DOS will prompt that the file is not found. Now I want to print the DOS prompt information into a txt file. How should I do it?
Floor 2 Posted 2004-03-08 00:00 ·  中国 广东 广州 电信
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
23-year member
UID 7105
Gender Male
Status Offline
Try this batch script
@echo off
copy \1dir\1.ext 2dir>3.txt
Floor 3 Posted 2004-03-09 00:00 ·  中国 山东 烟台 芝罘区 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
The method of gotomsdos doesn't work
Floor 4 Posted 2004-03-09 00:00 ·  中国 广东 佛山 三水区 电信
元老会员
★★★★
Credits 5,170
Posts 1,637
Joined 2002-10-16 00:00
23-year member
UID 8
Gender Male
From 广东佛山
Status Offline
Is this okay?
if exist \1dir\1.ext copy \1dir\1.ext 2dir>3.txt
if not exist \1dir\1.ext echo File not found.
我的网志
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
Floor 5 Posted 2004-03-10 00:00 ·  中国 山东 烟台 莱山区 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
The method on the 4th floor is quite tricky! But this "File not found" isn't from copy, though. Well, it's okay. If the poster doesn't have high requirements, this will do. It's much simpler than redirecting to an incorrect device.
Floor 6 Posted 2004-03-11 00:00 ·  中国 黑龙江 牡丹江 中移铁通
高级用户
★★
Credits 919
Posts 198
Joined 2004-01-17 00:00
22-year member
UID 15706
Gender Male
Status Offline
Floor 7 Posted 2004-03-12 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Use lmod

copy dir1\file1.ext dir2 > lmod /L* > 3.txt

lmod is a product of Horst Schaeffer. His products are good, but there are some minor issues under Chinese systems (it always shows "Invalid keyboard code specified" and then Chinese cannot be displayed). I really hope he can improve to support multi-language character sets.
Contact - Email: horst.schaeffer@gmx.net
Homepage: http://home.nikocity.de/horst.muc/int
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 8 Posted 2004-03-12 00:00 ·  美国
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
Horst's software needs no introduction. Most of his software, such as WBAT, cannot cooperate well with Chinese character systems.
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 9 Posted 2006-04-20 16:50 ·  中国 湖北 武汉 电信
新手上路
Credits 4
Posts 2
Joined 2006-04-20 15:54
20-year member
UID 54145
Status Offline
Is this problem unsolvable under pure DOS?!

When I use the del *.* command, if there are no files in the directory, there will be an error prompt, or if the file cannot be deleted, the same situation occurs. The method from the upstairs can't solve it, and I hope an expert can give guidance!
Floor 10 Posted 2006-04-21 16:11 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
Handsome guy~~ Give this a try

copy ..\楼主是帅哥.txt 2>帅哥是楼主.txt
Floor 11 Posted 2006-04-25 00:51 ·  中国 香港 环球全域电讯
初级用户
★★
Credits 121
Posts 61
Joined 2006-04-18 00:09
20-year member
UID 54007
Gender Male
From HK
Status Offline
Try using errorlevel... But it seems to make the problem more complicated
Floor 12 Posted 2006-04-25 17:19 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re WisdomNil:

Because in DOS, the error device cannot be explicitly redirected, and internal commands such as del/dir do not exit using INT 21/AH=4Ch, so no errorlevel is generated when an error occurs.

Therefore, so far, implementing error redirection to file output in the DOS command line or batch processing is an unsolved problem. The idea I have so far is to use a debug assembly script to redirect the error device or intercept the output of the screen buffer to a file, but it is relatively difficult to implement.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 13 Posted 2006-05-11 15:52 ·  中国 甘肃 兰州 中移铁通
初级用户
Credits 90
Posts 38
Joined 2006-01-06 18:41
20-year member
UID 48522
Status Offline
Originally posted by kcdsw at 2006-4-21 16:11:
Hey guy~~ Try this

copy ..\楼主是帅哥.txt 2>帅哥是楼主.txt

After testing, it is found that there are two types of so-called errors:
1. Command itself error
2. Parameter error
@echo off
echo Parameter error:>帅哥是楼主i.txt
echo ____________________>帅哥是楼主j.txt
echo Command itself error:>>帅哥是楼主j.txt
coby ..\楼主是帅哥.txt>>帅哥是楼主i.txt 2>>帅哥是楼主j.txt
::^^
copy 帅哥是楼主i.txt+帅哥是楼主j.txt errsum.txt
msg *<errsum.txt
del 帅哥是楼主i.txt
del 帅哥是楼主j.txt
del errsum.txt

1. The error message of "Command itself error" can be obtained by "2>";
2. The error message of "Parameter error" is obtained by ">";

[ Last edited by arding on 2006-5-11 at 15:59 ]
Floor 14 Posted 2006-05-11 19:53 ·  中国 山西 临汾 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re regarding:

All errors, whether they are errors of invalid command names, invalid command parameters, or errors during command execution, can be divided into two categories: those sent to standard error stderr and those sent to standard output stdout. Although both default to pointing to the console device, they use different ports.

And the copy command of cmd is somewhat special because it sends many errors through standard output, so we use >file to redirect these error messages, but most commands under DOS and CMD usually send error messages through standard error. Therefore, your dichotomy is not universal.

In addition, the error redirection discussed by the original poster is still limited to the DOS environment, and 2> in the CMD environment is not discussed.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 15 Posted 2006-05-12 09:24 ·  中国 甘肃 兰州 中移铁通
初级用户
Credits 90
Posts 38
Joined 2006-01-06 18:41
20-year member
UID 48522
Status Offline
Got it a bit. I don't have easy access to pure DOS here, and I've never delved deeply into these details. Do you mean focusing on this sentence:


Most commands usually emit their error messages through standard error.

If that's the case, can capture almost all errors using ERRORLEVEL or 2>?

[ Last edited by arding on 2006-5-12 at 09:28 ]
Forum Jump: