How can I both pipe and display output in Windows' command line?

Posted by Bob on Super User See other posts from Super User or by Bob
Published on 2014-06-12T01:38:07Z Indexed on 2014/06/12 3:29 UTC
Read the original article Hit count: 323

Filed under:
|
|
|
|

I have a process I need to run within a batch file. This process produces some output. I need to both display this output to the screen and send (pipe) it to another program.

The bash method uses tee:

echo 'ee' | tee /dev/tty | foo

Is there an equivalent for Windows? I am happy to use PowerShell if necessary.

There are tee ports for Windows, but there does not appear to be an equivalent for /dev/tty, which complicates matters.


The specific use-case here: I have a program (launch4j) that I need to run, displaying output to the user. At the same time, I need to be able to detect success or failure in the script. Unfortunately, this program does not set an exit code, and I cannot force it to do so. My current workaround involves piping to find, to search the output (launch4j config.xml | find "Successfully created") - however, that swallows the output I need to display. Therefore, I need some way to both display to the screen and send the ouput to a command - and this command should be able to set ERRORLEVEL (it cannot run asynchronously).

© Super User or respective owner

Related posts about Windows

Related posts about command-line