how to pipe output with double quotes

Posted on

Problem :

i want to pipe a URL to mplayer.
but can’t see how to encapsulate 1st output with double quotes (otherwise mplayer errors out)

this is wrong

youtube-dl.exe -g | mplayer


another option is to write/read from temp file.

Solution :

You do not want to pipe the result into mplayer, instead you want to supply the result as an argument, like so:

for /f "delims=" %A in ('youtube-dl.exe -g ""') do @mplayer "%%A"

If used within a batch file, then double up all percents, so %A becomes %%A.

I googled for an mplayer manual page; from what I can tell, it takes URIs as arguments. As I mentioned in the comments, you need to quote the YouTube URI. You’ll also need to quote the command substitution, so the shell doesn’t try to expand that into filenames, too. You want something like this:

mplayer "$(youtube-dl --get-url '')"

(--get-url is equivalent to -g; I changed it for clarity for those not familiar with youtube-dl.)

Leave a Reply

Your email address will not be published. Required fields are marked *