0

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?

João Pereira
  • 673
  • 1
  • 9
  • 29
  • 2
    You'll need to give information about what command interpreter or shell you are using - the way `system()` calls work varies depending on those (which is consistent with the effect of `system()` being implementation defined). However, assuming you are on a unix system, you will be better off using `fork()` and one of the `exec()` family of functions to execute your program. If you do that, an approach for redirecting output is at http://stackoverflow.com/questions/2605130/redirecting-exec-output-to-a-buffer-or-file – Peter Oct 16 '15 at 10:44
  • It's a program not done by me to simulate a LIDAR camera. It returns something like this: ` LIDAR Minimum = 0.000000 radians, maximum = 2 radians` – João Pereira Oct 16 '15 at 10:53
  • That's irrelevant, actually. `system()` typically launches a local shell which, in turn, executes your program. – Peter Oct 16 '15 at 13:02

1 Answers1

1

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.

Community
  • 1
  • 1
João Pereira
  • 673
  • 1
  • 9
  • 29