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-07-01 03:28
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » How to output to the screen? View 1,651 Replies 4
Original Poster Posted 2007-01-31 06:20 ·  中国 山东 济南 电信
新手上路
Credits 6
Posts 2
Joined 2007-01-31 05:46
19-year member
UID 78187
Gender Male
Status Offline
I wrote a BAT file. When outputting to a file, I want the screen to also display it. How to do this?
Floor 2 Posted 2007-01-31 06:31 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Forum search for tee.com

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 3 Posted 2007-01-31 06:43 ·  中国 山东 济南 电信
新手上路
Credits 6
Posts 2
Joined 2007-01-31 05:46
19-year member
UID 78187
Gender Male
Status Offline
Not found... How to make the screen display while doing dir >tt.txt?
Floor 4 Posted 2007-01-31 06:49 ·  中国 甘肃 兰州 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Floor 5 Posted 2007-01-31 11:33 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
It seems no one knows how to search.

http://www.cn-dos.net/forum/viewthread.php?tid=22281&fpage=1&highlight=tee.&page=2


willsort
Gold Member

Batchinger



Points 4224
Posts 1512
Registered 2002-10-18
Status Offline 『Post 19』:




Quote:
Originally posted by 3742668 at 2006-8-5 18:45:
The breadth of your knowledge determines the functionality of your scripts.



Re acoreq:

Indeed! The method we choose to solve a problem depends on how we understand the problem itself.

In your application, executing the command twice with or without & to redirect the output respectively may be the simplest solution. No matter how tedious it is, it is at least simple, and simplicity is not the same as conciseness.
========================================

But you may encounter some expected problems. For example, the output of some commands executed twice at different times is often different. For example, echo.%time%, executing it twice will get different results, and they are redirected to the file and the console respectively.

This is not the result we want, so we need to improve. The first thing that comes to mind is that we can first redirect all command output to a file, and then finally type this file to the console. This seems like a good solution. At least it solves the first problem, and it is also simple enough.

dir > cmd.log
cd >> cmd.log
...
type cmd.log
========================================

But there are still new problems. For example, in many cases, we want to be able to immediately view the output of some commands. We can type this file at this time, but if there are new command outputs to be redirected later, we face a dilemma: if we delete the command log after viewing the old command log, the log file will lack the previous command output; and if we don't delete it and continue to add new content with >>, then when we type later, the previous command output will be output to the screen again.

Therefore, the improvement needs to continue. Perhaps splitting the command log into multiple ones is a way - each command has a separate command log, which can be redirected and output independently without interfering with each other. Finally, if we want to get a complete log file, we just need to simply merge it with copy. This solution is still simple enough and can solve the current problems, unless there are new problems.

dir > _dir.log
type _dir.log
cd > _cd.log
type _cd.log
...
copy _*.log cmd.log >nul
del _*.log
========================================

However, if you consider yourself a very inquisitive (a synonym for being picky) batch processing designer, and therefore have some dissatisfaction with the above solutions (such as the temporary log files in the third solution), we need to find a more suitable solution.

First, I will think of a Unix tool called tee (a very strange name). It is a standard tool that outputs the text of the standard output to the console while outputting it to a file (it does not involve the concept of redirection, but essentially it is a similar mechanism). We can easily obtain the DOS or Windows port version of this tool .

Its usage is very simple, which was mentioned in

dir | tee cmd.log
cd | tee --append cmd.log
========================================

But if the "picky you" is resistant to third - party tools or has unavoidable difficulties (such as how to maintain cross - platform compatibility), then continue to find a new solution.

Soon you will find William Allen's vbs script , which is a first - party implementation of tee.exe, that is, we use the vbs script to complete the function similar to tee.

Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
Set Args=WScript.Arguments
LogFile=Args(0)
Set fso = CreateObject("Scripting.FileSystemObject")
Set LogFile= fso.CreateTextFile(Args(0))

Do While Not StdIn.AtEndOfStream
str = StdIn.ReadLine
StdOut.WriteLine str
LogFile.WriteLine str
Loop

LogFile.Close

Save this script as tee.vbs, and then we can use the following method to save the output of the command. Of course, we can simplify or enhance this script. For example, let it be able to add the command output to the log file instead of overwriting it.

dir | cscript//nologo tee.vbs cmd.log
========================================

Finally, if you are a pure DOS enthusiast and are not keen on vbs scripts. Then there will be an ASCode waiting for you to discover . This is another ASCode masterpiece by ASCII Assembler technology expert Herbert Kleebauer.

echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>tee.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>tee.com
echo @VyI?@xAp~sA`LZNxOq@Kt@FB?sUs`LbLB?tgj`{gjB~0x>>tee.com

The usage of this tee.com is not much more complicated than tee.exe and tee.vbs. And it has consistent performance under DOS/9X/NT. Except that this 16 - bit.com program will affect the code page of CMD@NT, and it is a bit difficult to understand, it should still be a perfect solution.

dir | tee > cmd.log
cd | tee >>cmd.log
========================================

TEE.EXE
http://www.cn-dos.net/forum/atta ... 62e9&download=1

How to display the execution result on the screen and save the result to
http://www.cn-dos.net/forum/viewthread.php?tid=21531

alt.msdos.batch.nt > Can you use redirection to two outputs?
http://groups.google.com/group/a ... sg/514d1343700b423e

alt.msdos.batch.nt > Tee
http://groups.google.com/group/a ... sg/b157065b8b12ebb2






※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +10 2007-02-01 06:59

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Forum Jump: