windows - how to pipe output with double quotes

07
2014-07
  • yoshco

    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 http://www.youtube.com/watch?v=sNPVt3cMkT0 | mplayer
    

    relevant?
    http://stackoverflow.com/questions/14952295/set-output-of-a-command-as-a-variable-with-pipes

    another option is to write/read from temp file.

  • Answers
  • dbenham

    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 "http://www.youtube.com/watch?v=sNPVt3cMkT0"') do @mplayer "%%A"
    

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

  • Blacklight Shining

    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 'https://www.youtube.com/watch?v=sNPVt3cMkT0')"
    

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


  • Related Question

    How to check return status of command invoked from command line in windows?
  • ashish
    reg import RegFile.reg
    

    How to check return code of this command ?


  • Related Answers
  • John T

    The exit status of the last command should be stored in the ERRORLEVEL variable. Run this after running your reg command:

    echo %ERRORLEVEL%