2

I am trying to run a C++ program and redirect the console output to a text file. From my understanding, this is achieved by:

./program > console.txt

I am able to compile and run the program using ./program fine and get the console output I am expecting. When I run ./program > console.txt nothing happens, I simply enter a linebreak and am on a new line in my console input (looks like the following)

$ ./program > console.txt


I have also tried append instead of redirect using ./program >> console.txt, as well as ./program | tee console.txt.

I know I can alter the C++ program to write to a file using <fstream> but I'd like to figure out why the redirect is not starting the program.

Thanks in advance!

christohew
  • 49
  • 3

1 Answers1

1

If you are redirecting to stderr, do ./program 2> console.txt. 2 is the file descriptor number for stderr.

stderr should only be used for error output.

user2233706
  • 6,148
  • 5
  • 44
  • 86