tags:

views:

112

answers:

3

I have a batch file containing a python script using the Output template> %(NAME)s when I ran it, cmd thinks its a var and igoners the % so

youtube-dl.py -b  -o %(uploader)s-%(title)s-%(id)s.%(ext)s 

turns into

youtube-dl.py -b  -o (uploader)s-(title)s-(id)s.(ext)s  

how do i convince cmd to not process it and pass it as is to python?

+1  A: 

Replace the % with %%:

youtube-dl.py -b  -o %%(uploader)s-%%(title)s-%%(id)s.%%(ext)s

(Note that, unlike on Unix, double quotes don't do a lot on Windows command lines.)

Tim Robinson
They do, but won't stop expansion of environment variables. How else would you include variable contents into a command line if it weren't for that?
Joey
+2  A: 

If you don't want your % characters interpreted by cmd.exe, you should prefix them with the escape character:

c:\> set qwert=55
c:\> echo %qwert%
55
c:\> echo ^%qwert^%
%qwert%
paxdiablo
+1  A: 

here's an alternative suggestion you don't have to meddle with cmd "quirks" like that you encountered. Pass to your script normal text arguments, then in your script, do the templating.

I suspect youtube-dl.py is not his script (I use something by the same name). But the suggestion is still good - instead of using batch, use your favorite scripting language. Since you have Python already on the system, use another python script, such as my-youtube-dl.py to set up your call to youtube-dl.
Jason R. Coombs