LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-03-2006, 09:33 PM   #1
code-breaker
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Rep: Reputation: 0
Bash script- capture cdparanoia text output


I'm new to linux, and am writing a bash script to automate the ripping/encoding process to backup my cd collection. My script is working very well. One thing I would like to add is the ability to add the cdparanoia version number to my log file. I know cdparanoia hasn't been updated in years, but this is more for learning than anything. I can't seem to capture the output of "cdparanoia -V". Even when I try to pipe it to a var in my script, it seems to print to the console no matter what. Am I doing something wrong?
 
Old 08-03-2006, 09:41 PM   #2
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
did you already tried to redirect stderr to stdout:
Code:
program 2>&1 | other commands
 
Old 08-03-2006, 09:41 PM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
It could be writing the info to stderr instead of stdout. Have you tried this:
Code:
cdparanoia -V > logfile 2>&1
 
Old 08-03-2006, 09:57 PM   #4
code-breaker
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Original Poster
Rep: Reputation: 0
Thanks for the quick reply, I'll give it a try...Can you provide a syntax to capture stderr output into a variable?
 
Old 08-03-2006, 09:59 PM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Code:
var=$(cdparanoia 2>&1)
 
Old 08-03-2006, 10:03 PM   #6
code-breaker
LQ Newbie
 
Registered: Jul 2006
Posts: 11

Original Poster
Rep: Reputation: 0
It worked! Thanks! ...But why would (what seems to be) standard output be stderr?
 
Old 08-03-2006, 10:06 PM   #7
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
It just depends on the program. If you want you can ask the cdparanoia devs.
 
Old 08-03-2006, 10:13 PM   #8
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Quote:
Originally Posted by code-breaker
But why would (what seems to be) standard output be stderr?
It's not unusual for scripts/apps to send messages to stderr instead of stdout - particularly where a "normal" exit means no output and a "0" status returned.

As far as why they look like the same thing goes, that just means that the current location for stdout was the same as for stderr. Try running ls -l /dev/stdout and ls -l /dev/stderr from a terminal and following the links. On the ssh window I have open at the moment, the output is:
Code:
$ ls -l /dev/stdout
lrwxrwxrwx 1 root root 4 2006-08-04 11:00 /dev/stdout -> fd/1
$ ls -l /dev/stderr
lrwxrwxrwx 1 root root 4 2006-08-04 11:00 /dev/stderr -> fd/2
$ ls -l /dev/fd/1
lrwx------ 1 steve steve 64 2006-08-04 13:06 /dev/fd/1 -> /dev/pts/3
$ ls -l /dev/fd/2
lrwx------ 1 steve steve 64 2006-08-04 13:06 /dev/fd/2 -> /dev/pts/3
The final location is the same (/dev/pts/3) so stdout and stderr will both display there.
 
  


Reply



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
Bash Script, calculate output. eldaria Programming 13 07-20-2006 09:26 PM
bash script Want to capture return key and assign a value procfs Programming 9 07-07-2006 01:38 AM
grab FTP output in bash script bokini Linux - General 2 02-03-2006 02:11 PM
bash script to output only differences in two files czarherr Programming 4 11-08-2004 06:25 PM
bash-script: output text between two ocurrences of a specific string isl01jbe Programming 1 06-17-2004 02:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:03 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
Open Source Consulting | Domain Registration