How do I redirect/save the console to a file and keep it visible on the screen?

13,658

Solution 1

In Linux, you can use the tee utility.

In Windows, PowerShell contains a tee cmdlet. For cmd, you will need to download and install a separate utility.

Solution 2

On Linux and similar systems:

program | tee filename

The tee program sends anything that comes into its standard input to its standard output (like cat) and also writes it to the specified file.

Another way to get the same effect would be

program >filename 2>/dev/null &
tail -f filename

This runs the program in the background, redirecting its standard output to the file, then tail -f lets you follow data being written to the file in real time (or nearly so, maybe a fraction of a second delay). The 2>/dev/null makes the standard error stream disappear so that it doesn't interfere with the output of tail -f.

Solution 3

Linux: command | tee logfile

Windows: Install cygwin, then run: command | tee logfile

Share:
13,658

Related videos on Youtube

sorin
Author by

sorin

Another geek still trying to decipher the meaning of “42”. It seems that amount his main interest are: online communities of practice and the way they evolve in time product design, simplicity in design and accessibility productivity and the way the IT solutions are impacting it

Updated on September 17, 2022

Comments

  • sorin
    sorin over 1 year

    I want to save a program's output (stdout) to a file but still be able to see the output on the screen in realtime.

    I need a solutions for both Linux and Windows.