Search code examples
bashshellshyoutube-dl

How to pass stdinput in a program running in background?


I have been trying to write a shell script which runs a command

youtube-dl -o C:\Users\3435\Desktop\35.mp4  http://www.youtube.com/watch?v=I1rxfwFxB8M

This command can be exited by typing q on shell.

I can pass the parameter to script but how to do it automatically from within the script or through the other script. I can kill this youtube-dl process from within the script but i dont want to do that as it effects the commad execution.

Kindly tell me how to make sure that q is being recieved by youtube-dl process either from another script or from within the same script.


Solution

  • You can redirect its standard input from a named pipe:

    mkfifo ydl-input
    youtube-dl -o 'C:\Users\3435\Desktop\35.mp4' \
               'http://www.youtube.com/watch?v=I1rxfwFxB8M' \
               < ydl-input
    

    then write "q" to the named pipe at any time later.

    echo q > ydl-input