You haven't shown the command you are using that is failing. If you show it in your question, it might be easier to find a solution for you.
I expect your command is something like this:
foo.exe|c:\Program Files (x86)\something\test.txt
The error you are receiving is somewhat of a clue:
'c:/Program' is not recognized as an internal or external command, operable program or batch file.
... is not recognized as an internal or external command, operable program or batch file.
This typically happens when you try to redirect to a file using a
| instead of a
When specifying a filename (or path) that contains spaces, you must surround it in double-quote marks (
"...") . This is because when the OS is determining the file to redirect to, it will stop looking for the filename when it encounters an unquoted space:
foo.exe>"c:\Program Files (x86)\something\test.txt"
If the above doesn't work to capture the output from
foo.exe to the text file, then there is another possibility...
If the program
foo.exe is writing its output to
STDERR instead of
STDOUT, the output of
foo.exe will not be captured by using simple redirection with a single
>. You would have to do it like this:
foo.exe>"c:\Program Files (x86)\something\test.txt" 2>&1
Here is an explanation of file redirection and the
When a program writes to the terminal, it can write to one of two
Stream 1 is referred to as
STDOUT or Standard-Output. Typically, programs write their "Normal" output to stream 1.
Stream 2 is referred to as
STDERR or Standard-Error. Typically, programs write their "Error" output (error and warning messages) to stream 2.
Whether a program writes a particular output to
STDERR is determined by the programmer and how they wrote the program. Some programs are written to send all output (normal output and errors) to
When a program is run with no output redirection, all normal and error output is sent to the terminal screen without any distinction between what is
STDOUT output or
When you do "normal" redirection with a single
> like this:
foo.exe > "c:\Program Files (x86)\something\test.txt"
you are not specifying which Stream is being redirected to the file, so Stream 1 is assumed.
It's the same as if you typed it like this:
foo.exe 1> "c:\Program Files (x86)\something\test.txt"
This tells the command interpreter (
cmd.exe) to capture the program output for
STDOUT (Stream 1) to the specified filename. The
1> refers to Stream 1.
In this case all the normal program is captured to the file, but if the program writes to
STDERR (Stream 2), that output will not be captured and will be shown on the screen. This is generally the "desired" way to do it so that while you are capturing the normal program output, you can see on the screen if an error occurs.
If you want to capture "Normal" output to one file, and "Error" output to a different file you can do it like this:
foo.exe > "c:\output.txt" 2> "C:\error.txt"
foo.exe 1> "c:\output.txt" 2> "C:\error.txt"
If you want the "Normal" output and the "Error" output to be captured to the same file, you can specify it like this:
foo.exe > "c:\output.txt" 2>&1
This is basically a "shorthand" way of specifying it and it means to redirect Stream 1 to the specified file, and to also redirect Stream 2 to the same "place" (file) as Stream 1.