LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash script- capture cdparanoia text output (https://www.linuxquestions.org/questions/linux-software-2/bash-script-capture-cdparanoia-text-output-470596/)

code-breaker 08-03-2006 09:33 PM

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?

konsolebox 08-03-2006 09:41 PM

did you already tried to redirect stderr to stdout:
Code:

program 2>&1 | other commands

gilead 08-03-2006 09:41 PM

It could be writing the info to stderr instead of stdout. Have you tried this:
Code:

cdparanoia -V > logfile 2>&1

code-breaker 08-03-2006 09:57 PM

Thanks for the quick reply, I'll give it a try...Can you provide a syntax to capture stderr output into a variable?

konsolebox 08-03-2006 09:59 PM

Code:

var=$(cdparanoia 2>&1)

code-breaker 08-03-2006 10:03 PM

It worked! Thanks! ...But why would (what seems to be) standard output be stderr?

konsolebox 08-03-2006 10:06 PM

It just depends on the program. If you want you can ask the cdparanoia devs. ;)

gilead 08-03-2006 10:13 PM

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.


All times are GMT -5. The time now is 07:36 AM.