How do I filter stdout of a program through grep while still controlling the program?
10,031
Solution 1
You can give mpv a fake terminal by using the script(1) program, for instance:
script -c 'mpv FILE' /dev/null | grep -v 'Error while decoding frame'
For Mac OS X, the syntax seems to be:
script /dev/null mpv 'FILE' | grep -v 'Error while decoding frame'
[edit: also check out Trick an application into thinking its stdin is interactive for additional solutions]
Solution 2
You can use nohup mpv FILE
. The output is written to nohup.out
which you can filter using tail
and grep
:
nohup mpv FILE
tail -f nohup.out |grep -v 'Error while decoding frame'
Related videos on Youtube
Author by
jaxuru
Updated on September 18, 2022Comments
-
jaxuru over 1 year
I'm trying to filter the output of the mpv media player, removing a particular line, but when I do so I am unable to control mpv with the keyboard. Here is the command:
mpv FILE | grep -v 'Error while decoding frame'
When I run the command, everything displays correctly, but I am unable to use the LEFT and RIGHT keys to scan through the file, or do anything else with the keyboard. How do I filter the output of the program while retaining control of it?
-
Anthon almost 9 yearsAre you sure
mpv
reads the keyboard if it detects it output is redirected to file? I.e if you dompv FILE > somefile.out
can you control it with the cursor? -
jaxuru almost 9 years@Anthon Oops, it doesn't, so would that imply that the place to look is mpv's settings?
-
Anthon almost 9 yearsMaybe there is some commandline switch for
mpv
. Quite a lot of programs actually detect if their output goes to a file (e.g. tryman | grep -F a
and you will not be able to scroll back and forth). -
jaxuru almost 9 years@Anthon there's a
--input-terminal
option but no dice, controls still changed, I think this is a dead end. Thanks for the help, though.
-
-
jaxuru almost 9 yearsWhen I try to use script, it doesn't allow a
-c
option... and there's no--version
option to try to see if its a version issue either. I'm running Mac OS Yosemite. -
remram almost 9 yearsYep, it's different; I added their syntax from the man page
-
Java Learner about 4 yearsTail just hangs waiting for text, even though mpv might have stopped producing output. If this is scripted, how do you detect EOF and exit?
-
Admin almost 2 yearsLove that this way I don't have to stop the ongoing command in order to tweak the grep.