Neil Mason
Neil Mason

Reputation: 96

Failing to redirect stdout or stderr of an executable in windows

I'm trying to redirect the output of a windows exe file that I received from a vendor. I don't have the code to this file and the vendor is a little hawkish, so sorry for the obfuscation.

Please not that I'm not trying to concatenate output and error together - I can't get either to redirect.

If I run it using powershell, I get the following

PS C:\test>.\vendor.exe
output
output
output
error
error
output

When I try to redirect stdout, I get the following.

PS C:\test>.\vendor.exe > output.txt
error
error

However whilst output.txt is created, it is an empty file. It appears of length 0.

Any ideas how to achieve the redirection, or if it is possible to prevent redirection in an exe?

Upvotes: 0

Views: 1730

Answers (1)

Bacon Bits
Bacon Bits

Reputation: 32145

You need to redirect standard error to standard out.

Try:

.\vendor.exe 2>&1 > output.txt

Here, 2>&1 says "redirect stderr to stdout" and > output.txt says "redirect stdout to output.txt".

Or:

.\vendor.exe *> output.txt

Here, *> output.txt says "redirect everything to output.txt."

The primary difference is that there are 6 output streams:

    1   Success output
    2   Errors
    3   Warning messages
    4   Verbose output
    5   Debug messages
    6   Informational messages 

See Get-Help about_Redirection.

Upvotes: 1

Related Questions