You are not logged in.
I am writing a script that I want to capture all STDOUT and STERR both. I know i can route both to screen with 2>&1, but....
I'd like both streams to go to the screen for viewing by person running the script, but I'd like to capture that output to a file at the same time as well, so I can send it to a logger tool.
Is this possible with piping magic?
Offline
Try this (untested).
for /f "usebackq tokens=1* delims=:" %%a in (`yourcommand 2^>^&1 ^| findstr /n ".*"`) do (
(<0 set /p "=%%b" & echo:) >&1
(<0 set /p "=%%b" & echo:) >&2
) 2>> yourlogfile.txt
Not sure what behaviour you'll see if your command is expecting user input.
Last edited by bluesxman (05 Feb 2020 15:45)
cmd | *sh | ruby | chef
Offline
Try this (tested ):
dir >myfile.txt
type myfile.txt
but if piped command requires user input, it will be taken first, before displaying output. It is the best solution for commands that does not require any input. Code above can work even on Windows and MS-DOS!
Last edited by Minecraft49 (12 Aug 2020 08:15)
Offline
It's fair comment that that could function as a minimum viable product, but not if you want real-time output from the command.
cmd | *sh | ruby | chef
Offline