开发者

literal usage of % in batch

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.%(ex开发者_高级运维t)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?


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.)


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%


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜