LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-03-2003, 10:30 AM   #1
legtester
LQ Newbie
 
Registered: Jul 2003
Posts: 4

Rep: Reputation: 0
Question 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!
 
Old 07-03-2003, 11:02 AM   #2
pilgrim22
LQ Newbie
 
Registered: Mar 2003
Location: TX
Distribution: SuSE/RedHat
Posts: 5

Rep: Reputation: 0
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
 
Old 07-03-2003, 11:34 AM   #3
legtester
LQ Newbie
 
Registered: Jul 2003
Posts: 4

Original Poster
Rep: Reputation: 0
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!
 
Old 07-03-2003, 02:37 PM   #4
dmx9595
Member
 
Registered: Jun 2003
Location: Canada,Ontario
Distribution: Debian and Gentoo
Posts: 135

Rep: Reputation: 15
using test like that is a common mistake heh i used to make that same mistake
 
Old 07-07-2003, 02:36 PM   #5
legtester
LQ Newbie
 
Registered: Jul 2003
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is output redirection? LinuxPadawan General 5 05-18-2005 12:53 PM
Output redirection rmartine Linux - Newbie 2 01-25-2005 06:31 PM
Output & input redirection serotonincy Programming 3 04-12-2004 08:28 AM
Minor output redirection problem.. Tyir Linux - General 0 01-27-2004 09:13 PM
output redirection to another directory spyghost Linux - Software 3 09-21-2003 09:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration