LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 04-04-2010, 01:25 PM   #1
qubuntu
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Rep: Reputation: 0
STDOUT redirection problem in BASH


Hi there

I'm trying to log serial data to a file using ttylog. It successfully outputs data to the screen using "ttylog -b 9600 -d /dev/ttyUSB0", but when I do "ttylog -b 9600 -d /dev/ttyUSB0 > x.txt" it creates the file, but it's empty.

Probably something obvious... Many thanks in advance.
 
Old 04-04-2010, 03:46 PM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
http://tldp.org/LDP/abs/html/io-redirection.html
 
Old 04-04-2010, 04:13 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Hi and welcome to LinuxQuestions!

If it's not standard output, maybe ttylog dumps the traffic to standard error. You can try to redirect it or both, using "2> x.txt" or "> x.txt 2>&1" respectively.
 
Old 04-05-2010, 07:55 AM   #4
qubuntu
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for your quick responses

Quote:
Originally Posted by colucix View Post
If it's not standard output, maybe ttylog dumps the traffic to standard error. You can try to redirect it or both, using "2> x.txt" or "> x.txt 2>&1" respectively.
I just tried that and it doesn't work either!

I just don't get it. If ttylog outputs stuff to the screen, why couldn't it be redirected? If I do "dir > x.txt" it works.

Has it got anything to do with me pressing Ctrl-C to stop ttylog?
 
Old 04-05-2010, 08:00 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by qubuntu View Post
I'm trying to log serial data to a file using ttylog. It successfully outputs data to the screen using "ttylog -b 9600 -d /dev/ttyUSB0", but when I do "ttylog -b 9600 -d /dev/ttyUSB0 > x.txt" it creates the file, but it's empty.
Does output appear on the screen?

Last edited by catkin; 04-05-2010 at 08:06 AM. Reason: Formatting
 
Old 04-05-2010, 08:11 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by qubuntu View Post
I just don't get it. If ttylog outputs stuff to the screen, why couldn't it be redirected? If I do "dir > x.txt" it works.
It would not work if ttylog was wrting to /dev/tty rather than stdout but the ttylog man page says it writes to stdout.

Quote:
Originally Posted by qubuntu View Post
Has it got anything to do with me pressing Ctrl-C to stop ttylog?
Possibly. stdout is buferred and, if it hasn't written enough to flush the buffer ... ?

Try ttylog -b 9600 -d /dev/ttyUSB0 2>x.txt >&2. It might work.
 
Old 04-05-2010, 09:06 AM   #7
qubuntu
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks everyone.

Quote:
Originally Posted by catkin View Post
Possibly. stdout is buferred and, if it hasn't written enough to flush the buffer ... ?
I think you're right. I just programmed an Arduino board to send cascades of random data at the serial port. If you run ttylog for a second or two, nothing gets written, but if you let it run for a bit longer the data gets redirected to the file.

Dunno if there's a way round that.
 
  


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
How to redirect standard stdout to multi stdout ( Bash )? john.daker Programming 4 11-04-2008 12:20 AM
Automatically stdout redirection to a file tikit Linux - Newbie 4 10-10-2008 06:18 AM
Bash I/O redirection problem R00ts Programming 1 10-26-2006 08:50 PM
redirection the process stdout do1do Linux - Security 3 11-24-2003 12:39 AM
redirection process stdout do1do Linux - General 2 11-23-2003 10:06 PM


All times are GMT -5. The time now is 09:19 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration