#1 04 Feb 2020 01:11

Registered: 28 Oct 2016
Posts: 18

Pipe output to file without removing from screen

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?


#2 05 Feb 2020 12:56

From: UK
Registered: 29 Dec 2006
Posts: 1,108

Re: Pipe output to file without removing from screen

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


Board footer

Powered by FluxBB