-1

I run a a program in command line (unix/linux). But I need to get the results into a file. So i used.

program_name >> result.txt

But it didn't give anything to the file. Then I tried.

program_name 2>> result.txt

Then I got a portion of the results which was part of the STD:ERR. But still some data shows on the console window. Is there any possibility to get that data to the file?

update: I also tried

program_name >> result.txt 2&>1

I get all data except two lines. Why I'm missing that?

  • 2
    [Redirect all output to file](http://stackoverflow.com/questions/6674327/redirect-all-output-to-file) – kaylum Dec 12 '15 at 10:00
  • This question is different. '*command* > file 2>&1' is also not working. But 'script outfilename.txt' before execution of the command shows full output – user3554510 Dec 12 '15 at 16:37

1 Answers1

1

You can send stdout to file and then redirect stderr to the same stream (&1) like this:

program_name >>result.txt 2>&1
Neil Masson
  • 2,609
  • 1
  • 15
  • 23
  • You mean some data is still sent to the console? – Neil Masson Dec 12 '15 at 16:14
  • No this time nothing is showing in the console. But data is missing in the file. But when it is not redirected to the file, I can see the missing portion of data in the console – user3554510 Dec 12 '15 at 16:30
  • One more update is : when I use 'script oufilename.txt' before executing my command, I can see full data – user3554510 Dec 12 '15 at 16:35
  • Possibly the program is sending output directly to the console device `/dev/tty` which bypasses the normal shell output streams. – Neil Masson Dec 12 '15 at 17:18
  • Ok. Then how can I get it into some file? I'm a beginner – user3554510 Dec 12 '15 at 18:14
  • As far as I know there is no clean way to do this. The best option is to modify the program - writing to /dev/tty is not portable. Otherwise there is nothing better than a hack like using `script`. – Neil Masson Dec 12 '15 at 19:52
  • This does not answer the question in the question's title. Does Linux have any other output streams apart from stderr and stdout? I am curious. – jg6 Aug 09 '20 at 14:35