Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I am working on an embedded product that has stdout going to the RS232 port (ttyS0 I think). So when I do a printf from my application it goes to this port. Sometime I will telnet into the system and I want to see those messages that are going out to the stdout on my telnet session.
So I am looking for a command line command that I can use once I log in with telnet; to redirect those messages from the stdout (ttyS0) to the telnet console.
If it does an "open(1,"/dev/ttyS0"...) or an fdopen/freopen, then you have no chance.
stdin/stdout/stderr are supposed to be inherited. The input/output/error output is opened by the login process which creates/initializes the pseudoterminal picked for the session. The three are then passed to the shell. Any program run under the shell will inherit these file descriptors - thus no need to "redirect".
"Redirection" is slightly a misnomer. What it does is direct the shell to open different files for stdin/stdout/stderr (whichever is being "redirected") after it forks a new process. Once the shell has opened these, the shell then execs the application, which inherits the open descriptors.
Problems will occur if the program is explicitly programmed to open stdin/stdout/stderr with another device/file. You can't redirect that as the program is overriding any redirection you can do.
As I understand it, the embedded systems boot without a terminal - which means no stdin/stdout/stderr. SOMETIMES the init process will open /dev/console (and have it associated with a serial line) and use that for stdout/stderr, then when the application is started it inherits the open files. Once the process is started, you don't change the output, though if /dev/console is what is opened, then you SHOULD be able to read from it, but doing so would require you to find out for your specific embedded system. Might also look for a /dev/log as sometimes this can be used (usually it is a socket, but I haven't used embedded Linux to have a good feel for what is/isn't available).
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
hmm, stdout is not the same as /dev/ttyS0, stdout is 'standard output' which is one of the three 'standard streams' http://en.wikipedia.org/wiki/Standard_streams which are entirely independant of the terminal in question, even DOS and windows command line applications use stdout,stderr and stdin for programs, so unless your program is for some reason hard coded to use /dev/ttyS0 for output then invoking the command via a telnet prompt SHOULD show you the output of the command
Not exactly sure what your requirements are. Perhaps what you're trying to do is read text that has already gone to /dev/ttyS0? As stated previously, standard streams are, well, standard. there's no reason to hard write into the devices as that stuff has been abstracted (for reasons.) One potential solution for what you may be trying to achieve is to use something like screen/tmux. Where you start your application in a screen/tmux window and can freely attach/detach to it from anywhere.
My application may be up and running for weeks before I log in with telnet (it is a commercial application). When I telenet in I would like to see the output messages (that the application is outputing to the stdout) on my telnet session. I hope that clears up my issue.
So from my telnet session I would like to do something like this.
Now, if you reprogram the application you could use a domain socket or a fifo perhaps - and only send data if the socket has something connected (the easy way is to set the socket/fifo file descriptor to non-blocking). This might even work if stdout is redirected (but stdout/stderr would still have to be set to non-blocking).