简体   繁体   中英

Can't redirect the output of system()

I'm running an executable in Linux in the terminal like so:

./foo 1 2 3 >output.txt

The results are not outputted to output.txt, even though the file is created but doing &>output.txt instead does the trick. So I guess the response of ./foo is defined as stderr??

But moving on.. my objective is to call that ./foo program within C multiple times but I'm not managing to get the output to a file when I do this:

status=system("./foo 1 2 3 &>output.txt")

The output only appears in the Eclipse console but the file is indeed created but remains empty. (I also tried > only)

Any idea on what I'm doing wrong?

Solution here: How can we redirect a Java program console output to multiple files?

The problem was that the eclipse console was "stealing" the output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM