Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.