LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Stop process while running script (https://www.linuxquestions.org/questions/programming-9/stop-process-while-running-script-565763/)

azazel11998 07-01-2007 03:30 AM

Stop process while running script
 
Hi everyone,

I am trying to get some information out of mplayer. I want to know the length of a video file. I used "-identify" switch it returns a whole bunch of information including something called "ID_LENGTH" which is exactly what I need. Here is what I do in the bash script. (I pass the name of the video file as an argument to the script)

Code:

mplayer -identify "$1" 2> /dev/null | grep "ID_LENGTH" > /tmp/out.$$
cat /tmp/out.$$ | cut -d"="  -f2,2

This actually returns the value that I need to get, but the problem is that I need to stop mplayer by hand. The output when I run the script should be the length of the file, without really running the file, so we should exit from mplayer as soon as we get "ID_LENGTH" field so that the script will continue and the length of the file will be outputed on the stdout.

Thanx in advance

jschiwal 07-01-2007 04:12 AM

You could run the mplayer process in the background and then use "kill -SIGQUIT %1" to kill it.
Code:

mplayer -identify "$1" 2> /dev/null | grep "ID_LENGTH" > /tmp/out.$$ &
sleep 5
cat /tmp/out.$$ | cut -d"="  -f2,2
kill -SIGQUIT %1

I don't know if 5 seconds is enough time to locate the video.


All times are GMT -5. The time now is 08:05 AM.