LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices


Reply
  Search this Thread
Old 08-08-2014, 12:44 PM   #1
weaver4
LQ Newbie
 
Registered: Aug 2014
Posts: 3

Rep: Reputation: Disabled
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

Last edited by weaver4; 08-08-2014 at 01:48 PM.
 
Old 08-08-2014, 03:57 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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).

Last edited by jpollard; 08-08-2014 at 04:08 PM.
 
Old 08-08-2014, 05:26 PM   #3
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
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
 
Old 08-09-2014, 12:57 PM   #4
zer0python
Member
 
Registered: Sep 2003
Posts: 104

Rep: Reputation: 20
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.
 
Old 08-10-2014, 02:04 PM   #5
weaver4
LQ Newbie
 
Registered: Aug 2014
Posts: 3

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

Last edited by weaver4; 08-10-2014 at 02:13 PM.
 
Old 08-10-2014, 02:07 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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).

Last edited by jpollard; 08-10-2014 at 02:13 PM.
 
Old 08-10-2014, 02:20 PM   #7
weaver4
LQ Newbie
 
Registered: Aug 2014
Posts: 3

Original Poster
Rep: Reputation: Disabled
OK, thanks; I thought that is the way the answer would go.

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


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirecting stdout instantaneously... ramesh6056 Linux - Software 8 10-04-2007 11:15 AM
Redirecting stdout, stderr to pty0? Rostfrei Linux - General 4 03-20-2007 03:15 AM
redirecting stdout to /dev/null and stderr to stdout? Thinking Programming 1 05-18-2006 02:36 AM
Redirecting to file and stdout Quantum0726 Programming 3 11-14-2005 08:35 PM
Redirecting stdout to tar hari_s_82 Linux - Newbie 6 10-08-2004 01:49 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:15 AM.

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