Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.


  Search this Thread
Old 12-15-2010, 12:53 PM   #1
LQ Newbie
Registered: May 2010
Posts: 5

Rep: Reputation: 0
Question Redirecting console output from a Qt application to a telnet session

if been struggling with this problem for a while now.

I've got an embedded Linux running on an ARM platform (Freescale iMX257).
The bootloader (RedBoot) starts Linux with the option
When Linux is started, it automatically starts a dedicated Qt application.

When I'm connected via the UART, my terminal program will let me type commands and get output from my running Qt application.

But when the module is in the field, I want to access it via Telnet, as there won't be a UART connection, only LAN.
I can open a telnet session, which will let me type commands and get output from those commands. But I can't see the output of my Qt application as this is still emitted on the UART.

How can I redirect the output of that application to the telnet session?

I thought this would do:
(via telnet on ttyp0)
$ cat /dev/console > /dev/ttyp0
Now everything I type through the UART appears on the telnet session. But I can't execute it, nor can I see the output of my Qt application.

I tried to modify the command running my application in the /etc/inittab:
./myQtApp > /dev/ttyp0
but now the application won't start before I've opened the telnet session. Even then, only 'some' output from my App is passed to the telnet session (output written by "std::cout", output written by Qt's "qDebug()" function is still on the UART...)

I started playing around with /dev/ttymxc0 as well, but without result...

What am I doing wrong here?

Thanks in advance!
Old 12-16-2010, 03:10 AM   #2
Registered: Nov 2010
Location: Thailand
Distribution: Fedora 12, Ubuntu 10.10
Posts: 166

Rep: Reputation: 29
Can you redirect the output of Qt in a file (e.g. in the ramdisk or storage), then telnet and read the file ?

start script:
./myQtApp > /tmp/qt_debug.log 2>&1
tail -f /tmp/qt_debug.log

If you need to limit the size of the log, use logrotate
Old 12-16-2010, 10:50 AM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
I have solved a similar problem by launching applications in a Gnu screen session that is running in multi-user mode. Then, I can attach and detach from the session at arbitrary times or from various connection methods (serial console, telnet, ssh, etc.).

--- rod.
Old 12-16-2010, 11:32 AM   #4
LQ Newbie
Registered: May 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the hint.
Although I'd rather avoid using a file (as there isn't much spare space on the device), you gave me a valuable hint:

I added the " 2>&1" to my start-myQtApp script that's called by inittab:
./myQtApp > /dev/ttyp0 2>&1
Now it works! So Qt's qDebug() writes to stderr...

So now I can:
-open a telnet session
-vi start-myQtApp and add the redirection
-kill myQtApp
-myQtApp will respawn and be redirected to the telnet session.

It's a start but it includes killing myQtApp, which can cause loss of valuable information about the state the application was in before I killed it.

I also can't add the redirection to start-myQtApp as a default, because then I get the following error when the app starts when the telnet session is not active (=99% of the time):
can't create /dev/ttyp0: Input/output error
and the app is never started...

My question boils down to this:
Is there a way to redirect the stdout/stderr stream of a *running* application?

I already found some solutions involving the use of external programs
(using gdb, using screen), but again these take a lot of space in my file system.
I like the way they do it with gdb. But can't this be done without that workaround?

Last edited by bameije; 12-16-2010 at 12:00 PM. Reason: extra info
Old 01-21-2011, 10:32 AM   #5
LQ Newbie
Registered: May 2010
Posts: 5

Original Poster
Rep: Reputation: 0
Hi all,

I found it.

The solution is to add this to the program code: (c++)

void redirect( QString device )
  freopen( device, "w", stdout );
  freopen( device, "w", stderr );
Now, I can start a telnet session, send a command to my application (using an interface that I already had) that requests a redirection. The string argument 'device' is set to the tty of the telnet session.

I haven't found a solution that does this without editing the source code. (except using screen or gdb, which wasn't an option for me)


console, qt, redirect, telnet, tty

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 physical console output pwalter Linux - Newbie 3 05-13-2009 08:18 AM
Redirecting output from screen to console from boot-up ? exceed1 Linux - General 3 11-23-2008 11:26 PM
console formatting over telnet session mikoroz Linux - Newbie 2 11-12-2007 04:57 AM
get output from telnet session? Manana Linux - Networking 4 01-24-2007 03:20 AM
Pipe telnet session output to text file joshlamerritt Linux - Software 3 02-10-2004 09:42 PM > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

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

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