Copy all command line output to file

Hi,
I want to copy everything that gets printed to command line at any point of execution to a separate file. Basically creating a log of anything that is printed to command line, including errors.
How do I do this using Intel Fortran?
Thank you!

You can use “tee” in the command line interface, in linux. This duplicates the output to a file. Or you can use a pipe.

If you are using windows, I cannot help, but I guess there are similar options.

Thank you! Unfortunately, I am using Windows - if anyone has suggestions, that would be much appreciated!

For cmd.exe under windows, see Using command redirection operators | Microsoft Learn

Use fortran units 6 and 0 for stdout and stderr respectively, or the values in the intrinsic module iso_fortran_env

Under Mac/Linux you should be able to

tail -f monitoring_your_program.log

Under Windows (powershell), there is Get-Content. I’ve never used it myself, but google gives me

Get-Content monitoring_your_program.log -Wait -Tail 30

I see, thank you all. So I have to use a shell? I was just running everything directly in Visual Studio… Sorry if this is a silly questions, complete beginner here…

Yes, but the OP wants the output to go both to the screen and a file. Windows PowerShell has tee. If you have an executable a.exe in the current directory, the syntax to run it with tee is

.\a.exe | tee some_output_file.txt

Windows CMD does not have tee, but Cygwin does, and I checked that it worked for a simple Fortran program.

Whoa, that little line of code was super helpful! It works now - thanks so much everyone!!

1 Like

@bananarama ,

See this also: an option still supported on Windows from the old days of DOS: