Is there a Windows equivalent of the script command in Linux?

No, there is no Windows equivalent to the script command; believe me, I have searched high and low.

In any case, you can use redirection to accomplish at least half of it. You will not see the output during execution, but you can see it afterwards in the file. Unfortunately it’s a compromise, but it can do when in a pinch.

The only thing that you need to look out for is that some programs write to more than one stream. In addition to standard out (stdout), they may also write to standard error (stderr) or standard log (stdlog). So to make sure that you capture all output, you need to redirect both stdout and stderr (in Windows, stdlog is automatically redirected to stdout). In the example below, the Microsoft compiler (cl.exe) prints the banner (header text) to stderr, and the rest of the help text to stdout.

C:\> cl /? > foobar.txt 2>&1

I am afraid copy-paste is the only way (redirecting output is not script command equivalent).

According to Microsoft Help Forum

Open the cmd prompt in a window format, i.e. not full screen...

Now right click on the head of the cmd promt, i.e. the blue strip on the top and there is a option of edit. There select the option mark, i.e. edit->mark,.You will get a cursor in the cmd promt, just select the area that you want to copy... then again go to the top right click edit-> copy

Now in a text file just paste and you will get the contents of the cmd prompt in the text file...


There are workarounds to do what you want.

The cygwin utility package (google cygwin to find it) actually has a script command. If you install that package, modify your PATH variable appropriately, and type script -c cmd it will start a dos shell and capture the input and output in a file named typescript. The script command has several options. (I leave it as a exercise for the reader to find the documentation :)

Cygwin will install lots of stuff on your computer. If you want to keep it simple you can install the tee command as mentioned above and type cmd | tee filename-of-your-choice. This will capture the input and output in filename-of-your-choice.

Here is an log of the second solution. Notice that the logged input and output is in a subshell. (I would have posted a screenshot but this site won't let me - I haven't talked enough).

Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft
Corporation.  All rights reserved.

C:\Users\David>echo topshell topshell

C:\Users\David>doskey /h echo topshell doskey /h

C:\Users\David>cmd | tee log.txt Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\David>echo subshell subshell

C:\Users\David>doskey /h echo subshell doskey /h

C:\Users\David>exit

C:\Users\David>doskey /h echo topshell doskey /h cmd | tee log.txt
doskey /h

C:\Users\David>type log.txt Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\David>subshell

C:\Users\David>echo subshell doskey /h

C:\Users\David> C:\Users\David>

I just tried both solutions. The second (cmd | tee ...) is better as it allows command recall with the arrow keys. The first solution (script.exe) does not.

Tags:

Windows

Batch