Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How to tee STDERR on Windows

by Marshall (Canon)
on Jan 13, 2022 at 08:15 UTC ( [id://11140420]=note: print w/replies, xml ) Need Help??


in reply to How to tee STDERR on Windows

Interesting question. Windows supports redirection of STDERR and STDOUT, like test.pl >log 2>&1 will send both to a file. "tee" is available in the powershell. just typing "powershell" at the windows cmd prompt will start the powershell. But the problem is that there is no easy way to pipe STDERR into another program like tee. You can tee STDOUT and send STDERR to a file, but you want both on the screen and in the file.

This is one heck of an ugly Win10 command line solution. But I tested this on my machine and it does work. I admit that I am still struggling to understand exactly why it works. I make no claims other than I did test this on Win10 home edition with an actual Perl program.

Win10prompt>for /f "delims=" %L in ('perl testchompwhile.pl 2^>^&1') do @echo %L & echo %L >> log

I happened to have a short Perl program that I wrote for another post for testing. This appends both STDERR and STDOUT to log and of course the also both go to screen as requested.

update: The only other info I have about this is: "The for command iterates over the output lines of the script. The carets escape the characters that follow them. The first echo goes to the screen and the second is appended to the file named "log"."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11140420]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-24 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found