views:

41

answers:

2

Hi, I am running a C++ program and there are other underling code.

When I run it, suppose it is a.exe, there are a lot of information printed on the screen. I can't redirect some information to a .txt file like ./a.ext > temp.txt

How can I force it is redirect to the temp.txt?

Thanks!

+2  A: 

POSIX

Reditect STDOUT and STDERR

./a.ext &> temp.txt

Or you can use equivalent from windows format.

./a.ext >& temp.txt

Windows (Reditect STDOUT and STDERR)

Reditect STDOUT and STDERR

./a.ext >& temp.txt

More information about this you can find at Using command redirection operators at Microsoft Technet

Svisstack
@skydoor: the reason this works is that your output is probably going to stderr, and the above is redirecting stderr (and stdout?) to temp.txt.
LarsH
Svisstack
A: 

Some of the information may be written stderr. In order to catch both stdout and stderr, you should use

./a.ext > temp.txt 2>&1
doron
@deus: In what shell environment?
LarsH