Dos and/or Windows versions of Unix SCRIPT command
Back in university, when we had to submit an assignment in CS, we would have to perform a series of steps including running script, date, whoami, etc.
, and then running our program.
The script
command would pipe all text sent to the display to both the display and a specified file as well.
Ever since, I have been looking for a Dos and/or Windows version, but have come up empty. Some programs can be redirected to a file, but then the display is not echoed, and some programs don’t seem to work with redirection at all.
Any ideas?
Edit:
So far, the answers that I’ve gotten seem to work exactly like the standard redirection commands (<, >, |
). These do not work with all programs. For example, the Microsoft C++ compiler CL.EXE. If you run cl /?
through a redirection command or pipe it through another program (such as TEE), you will not get the header/banner text.
Another example is a program I wrote a while back in Pascal (I think the last compile was in FreePascal). The help text does not get redirected at all. I have seen this occur with other programs as well like MKISOFS. It has a long help text, but cannot be paused by piping it through MORE or redirected to a file!
I have wondered about this for many years. I used to think that it may be because the text is being written directly to the screen (eg port B800) or something, but I have yet to pin down the cause, let alone find a program that can do this job.
Solution 1:
Take a look at Cygwin, it gives you access to all those great UNIX command line tools in Windows.
Solution 2:
Okay, so as usual, I took it upon myself to write the program. I had a bit of free time tonight and threw together a native (ie, non-Cygwin) test program that works exactly as I had hoped, albeit with two limitations. (I don’t have an always-on host, but I’ll see to cleaning up the program, writing docs, and releasing it.)
-
It cannot capture output from programs that write directly to the video hardware (or virtualized hardware as the case may be), so the Pascal program I mentioned cannot be captured unless I recompile it without the direct flag set—which incidentally became unnecessary when I recompiled it with FreePascal.
-
It cannot receive input from stderr. For example, if you execute
cl /? | script.exe c:\test.log
, only the help text of the Microsoft compiler will be sent to the file; the banner will only be displayed on the screen. (This is somewhat baffling due to the way the program works, so I’m going to look into it.)
There’s little that can be done about problem (1) (I would not be surprised if there were some clever person somewhere who could figure out a way to intercept direct screen writes, but for all intents and purposes, it’s probably unlikely.)
Problem (2) can be worked around by redirecting stderr to stdout before piping it as follows. It’s not pretty (or as convenient, but it works).
cl /? 2>&1| script.exe c:\test.log
It may/should also be workable from program’s side, thus simplifying the pipe, but I have yet to find any information on how (at least in a “normal/official” way, eg via C++). I do have an idea about installing an interrupt handler in the interrupt vector table to intercept calls to the common ouput API functions, which may/probably will work. In fact, in 1998, I had written an experimental DOS TSR (that also works in the Windows NTVDM), which intercepts output functions and colors them (ie, generic syntax-coloring) before sending them to the screen. It would/should be easy to adapt it to also send a copy to a file.
Solution 3:
Unfortunately, it seems that you won't have luck finding an out-of-the-box Microsoft solution. You can check out a similar post on StackOverflow. The digest:
- look at the Win32 port of tee on SourceForge
- use Cygwin, as Frank Szczerba also mentions
- look at Rob van der Woude's tee implementation in a DOS Batch script
- a couple more opinions