Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to view mplayer's normal terminal output, and also write it to a log.
That works fine when I run mplayer from the commandline, eg:

mplayer "$HOME/gdr01.wav" 2>&1 |tee $HOME/junk.log

However, I want to launch mplayer in it's own gnome-terminal window. Neither of the following commands write to the log, althought the terminal display works.

(gnome-terminal -e "mplayer $HOME/gdr01.wav 2>&1 |tee $HOME/junk.log" &)
 gnome-terminal -e "mplayer $HOME/gdr01.wav 2>&1 |tee $HOME/junk.log" &

What is at play here, and what is the trick to get it to work?

EDIT: The problem is that I get the terminal's mesages being written to the log (eg. an ibus warning). However, although mplayer generates thousands of lines, none are written to the log.

share|improve this question
add comment

3 Answers 3

up vote 3 down vote accepted

What's going on is that gnome-terminal's command line parsing is funky. You're running mplayer with /home/ferer/gdr01.wav, 2>&1, |tee and /home/ferer/junk.log as arguments. If you wait for the end of the audio file, you'll see error messages about these nonexistent files for a microsecond before the terminal closes.

Either figure out gnome-terminal's intricate rule. Or, what I recommend: yse the -x option instead of -e and invoke a shell explicitly.

gnome-terminal -x sh -c 'mplayer "$HOME/gdr01.wav" 2>&1 |tee $HOME/junk.log'
share|improve this answer
    
@Gilles: Thanks.. This is still a fuzzy issue to me, but I haven't noticed any discernable difference in how -x vs -e work, other than the quoting syntax. However, in the last hour, I stumbled on the same shell method you've suggested, when I recalled noticing that when mplayer is run directly from the CLI, its parent is bash, but when launched as an arg to gnome-terminal its parent is gnome-terminal... so I added 'bash -c' and it worked.. I don't quite understand why.. Is it that this immediate parent layer is needed to handle the io-redirection? I suppose it is... –  Peter.O Nov 25 '11 at 2:20
    
@ferer With -e, gnome-terminal does its own vaguely shell-like parsing of the argument (in simple cases, it splits at spaces, but that's not all it does) but does not actually invoke a shell. With -x, gnome-terminal invokes the given program with exactly the given arguments. –  Gilles Nov 25 '11 at 2:28
1  
(a general note to readers).. Just so that I won't have to export my vars (other than known environment vars like $HOME, which are already "exported"), I've used a variant of Gilles' command; here it is: gnome-terminal -x sh -c 'mplayer "$1" 2>&1 |tee "$2"' 0 "$aud" "$log" ... The 0 is just a placeholder for what typically is $0. The two args which follow the 0 are $1 and $2 ..(the 0 can be whatever you like)... –  Peter.O Nov 25 '11 at 7:29
add comment
gnome-terminal -x mplayer $HOME/gdr01.wav 2>&1 |tee $HOME/junk.log &

This command at least creates the log file.

share|improve this answer
    
Your command behaves exactly the same as mine (-x vs -e). The problem is that it produces a log of the terminal's output, but not of what mplayer outputs.. It gives 1 line in the log (an ibus warning). This same message appears in the log even when not launching mplayer, eg. gnome-terminal 2>&1 |tee $HOME/junk.log & ... mplayer's output is thousands of lines long (although it appears on screen as a recurring overlaid line); it generates approximately 4-5 lines per second, but they don't end up in the log. –  Peter.O Nov 25 '11 at 0:25
add comment

I would try to put exec in front of mplayer, since it is running it on a different shell.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.