中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-15 13:29
47,812 topics / 349,917 posts / today 0 new / 48,268 members
DOS批处理 & 脚本技术(批处理室) » How to print DOS error messages to a txt file?
Printable Version  6,736 / 18
Floor1 IceFire Posted 2004-03-04 00:00
初级用户 Posts 1 Credits 104
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?
Floor2 GOTOmsdos Posted 2004-03-08 00:00
铂金会员 Posts 1,827 Credits 5,154
Try this batch script
@echo off
copy \1dir\1.ext 2dir>3.txt
Floor3 qzwqzw Posted 2004-03-09 00:00
银牌会员 Posts 636 Credits 2,343
The method of gotomsdos doesn't work
Floor4 MYS Posted 2004-03-09 00:00
元老会员 Posts 1,637 Credits 5,170 From 广东佛山
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.
Floor5 qzwqzw Posted 2004-03-10 00:00
银牌会员 Posts 636 Credits 2,343
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.
Floor6 moroko Posted 2004-03-11 00:00
高级用户 Posts 198 Credits 919
Floor7 Climbing Posted 2004-03-12 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
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
Floor8 Wengier Posted 2004-03-12 00:00
系统支持 Posts 10,521 Credits 27,736
Horst's software needs no introduction. Most of his software, such as WBAT, cannot cooperate well with Chinese character systems.
Floor9 WisdomNil Posted 2006-04-20 16:50
新手上路 Posts 2 Credits 4
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!
Floor10 kcdsw Posted 2006-04-21 16:11
中级用户 Posts 179 Credits 404
Handsome guy~~ Give this a try
Floor11 tsenix Posted 2006-04-25 00:51
初级用户 Posts 61 Credits 121 From HK
Try using errorlevel... But it seems to make the problem more complicated
Floor12 willsort Posted 2006-04-25 17:19
元老会员 Posts 1,512 Credits 4,432
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.
Floor13 arding Posted 2006-05-11 15:52
初级用户 Posts 38 Credits 90
Originally posted by kcdsw at 2006-4-21 16:11:
Hey guy~~ Try this

After testing, it is found that there are two types of so-called errors:
1. Command itself error
2. Parameter error

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 ]
Floor14 willsort Posted 2006-05-11 19:53
元老会员 Posts 1,512 Credits 4,432
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.
Floor15 arding Posted 2006-05-12 09:24
初级用户 Posts 38 Credits 90
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 ]
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023