LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Redirecting stdout to telnet (https://www.linuxquestions.org/questions/linux-newbie-8/redirecting-stdout-to-telnet-4175514000/)

weaver4 08-08-2014 12:44 PM

Redirecting stdout to telnet
 
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.

Thanks

jpollard 08-08-2014 03:57 PM

depends on the application.

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).

frieza 08-08-2014 05:26 PM

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

zer0python 08-09-2014 12:57 PM

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.

weaver4 08-10-2014 02:04 PM

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.

&1 >> my-telnet-session

jpollard 08-10-2014 02:07 PM

Then you need it to be sent to a rotating log...

You won't be able to get it any other way.

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).

weaver4 08-10-2014 02:20 PM

OK, thanks; I thought that is the way the answer would go.

With Linux you never know what you don't know.


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