我需要在\r\n
参数中使用ffmpeg --header
。这适用于Unix,但不适用于Windows命令提示符。所以我想知道使用powershell
powershell c:\ffmpeg -headers 'User-Agent: user-agent'"`r`n"'Cookies: my-cookie' ...
我知道当使用特殊字符时我必须使用'string'
"`r`n"
作为我的\r\n
分隔符。
我还测试过我可以将它们混合在一起,比如'this '"is "'text'
来获得this is text
但是,如果我的字符串(cookie或用户代理)包含&
字符,则会失败。
示例:powershell c:\ffmpeg -headers 'Cookies: param=a=1&b=2; session=123'
如何在单行中“逃脱”&
角色?
这些示例(某些部分被屏蔽)被CMD接受,但它们不起作用
powershell -c "c:\ffplay -user_agent ""Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0"" -headers ""Cookie: nlqptid=h=676886edeea5bae904b0cf53daec8038.1519940538670&hdnea=exp=1519940598~acl=/*~hmac=C0E019502B060D23AB02BB157FCFFC72404500770A2CE5B00789A84AAEFBD77F&nltid=xxxxxxxxxx&nltdt=0&uid=744826&csid=xxxxxxxxxx; hdntl=exp=1520026938~acl=%2f*~hmac=952689e6de57a2a201ddc1d4c0794962fdc886ea48cf41494a42e787ef923bf9`r`n"" -i ""https://xxxxxxxxxx.net/nlds_vod/xxxxxxxxxx/vod/2018/02/28/cd264e10-dd54-3de2-df90-4c1cac104dcb/v1/stream/cd264e10-dd54-3de2-df90-4c1cac104dcb_1_4500_pc.mp4.m3u8"""
要么
powershell -c "c:\ffplay -headers ""User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0`r`nCookie: nlqptid=h=676886edeea5bae904b0cf53daec8038.1519940538670&hdnea=exp=1519940598~acl=/*~hmac=C0E019502B060D23AB02BB157FCFFC72404500770A2CE5B00789A84AAEFBD77F&nltid=xxxxxxxxxx&nltdt=0&uid=744826&csid=xxxxxxxxxx; hdntl=exp=1520026938~acl=%2f*~hmac=952689e6de57a2a201ddc1d4c0794962fdc886ea48cf41494a42e787ef923bf9`r`n"" -i ""https://xxxxxxxxxx.net/nlds_vod/xxxxxxxxxx/vod/2018/02/28/cd264e10-dd54-3de2-df90-4c1cac104dcb/v1/stream/cd264e10-dd54-3de2-df90-4c1cac104dcb_1_4500_pc.mp4.m3u8"""
ffplay
说
必须指定输入文件
但输入文件是在-i
参数之后指定的。
这个命令有什么问题?
请注意,实现是现有批处理脚本的一部分,因此需要使用在批处理文件内部工作的语法。
从cmd.exe
打电话时,事情变得棘手;这是一个简化的例子:
powershell -c "ffmpeg.exe -h \""User-Agent: usra`r`nCookies: parm=a=1&b=2; session=1\"""
简而言之:要传递PowerShell应该看作双引号的参数,请在\""...\""
中将每个参数放在整个"..."
字符串的上下文中。[1]
作为一般要求,字面%
字符。必须作为%%
进行转义,以防止它们被解释为批处理文件中cmd.exe
变量引用的一部分。从命令提示符,things are unfortunately more complicated。
"..."
封闭的字符串传递,通过参数-c
(-Command
的缩写,在Windows PowerShell中是默认值,但在PowerShell Core中已更改,现在默认为-File
)。cmd.exe
只承认"..."
引用,并且只在"..."
内部是元字符,例如被视为文字的&
。"..."
,因此为了PowerShell,嵌入式"
实例必须作为\"
进行转义(请注意,使用了PowerShell-internal `"
)。\"
本身然后使cmd.exe
认为随后的字符在其"..."
字符串之外,导致&
等字符打破调用,因此"
之后的\
必须加倍,产生\""
(sic)的整体转义序列嵌入式和配对双引号。暂且不说:'this '"is "'text'
不像Bash那样创建单个字符串;在PowerShell中:
('this ' + "is " + 'text')
[1]虽然这种方法永远不会破坏,但它确实规范了\""...\""
序列中的空白;也就是说,多个空格的运行每个都用一个空格替换。
如果这是一个问题,你必须使用\"...\"
和单独的^
-escape cmd.exe
metacharacater,如^
里面。