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:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!