LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Output redirection (https://www.linuxquestions.org/questions/linux-general-1/output-redirection-69832/)

legtester 07-03-2003 10:30 AM

Output redirection
 
Hi everyone,

I am having a problem with redirecting ouput from a command line program. Usual commands > or >> do not come back with an error and the program appears to run, but doesn't complete. The output file I specify is always empty (size 0K).

I've been checking directory and file permissions, and path issues, but not coming up with any problems. Some syntax I've tried:

/usr/bin/tslg > /usr/bin/test

/usr/bin/tslg > test

tslg > test

/usr/bin/tslg >> test

Can anyone give me any ideas of what might cause this?

Thanks!

pilgrim22 07-03-2003 11:02 AM

Yikes! :O "test" is a shell command, and /usr/bin/test is the program it calls. I would use a different output file name first, like tslg.out or something. You may have overwritten a fundamental shell command!!!

If you still don't get output in your file-with-a-new-name, does your proggie produce output on the screen when run without redirection? If so, it may be sending output to the standard error stream (stderr in C/C++). Try adding "2>&1" to your command (without the quotes) which will redirect stderr to standard out, which will then go to your file.

HTH
pilgrim22

legtester 07-03-2003 11:34 AM

Yikes is right, I regularly use 'test' for file names! Thanks for that.

I am now using 'new'. :-) But still no output. If I remove the redirection my command works perfectly and sends 5 lines of output to the screen. After some more experimenting, I believe there is something unique to this program that is preventing the output from being redirected. The command

tslg | wc results in 0 0 0

and

tslg | less results in END

I'm planning to talk to the programmer who wrote 'tslg' but of course, he is gone for the week.

Ever seen something like this before?

Thanks again!

dmx9595 07-03-2003 02:37 PM

using test like that is a common mistake heh i used to make that same mistake :D

legtester 07-07-2003 02:36 PM

For anyone who was following this thread...this was due to syntax in the program itself. Here is the info from the engineer who fixed the redirection problem:

I was calling _exit() at the end rather than exit(), and I'm assuming that one of the differences is that exit() flushes the output buffers, which is what seems to make the difference when piping output.


All times are GMT -5. The time now is 08:36 AM.