我有一个命令可以正常使用命令提示符:
CMD /C ""C:\Program Files (x86)\VideoLAN\VLC\VLC" -vvv "http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO==" :sout=#file{dst="F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4",no-overwrite} :sout-keep""
这里我需要CMD /C
来返回错误级别。
这就是我尝试使用Run
方法在VBScript中运行它的方法:
WshShell.Run "CMD /C ""C:\Program Files (x86)\VideoLAN\VLC\VLC" -vvv "http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO==" :sout=#file{dst="F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4",no-overwrite} :sout-keep""", 0, False
此命令将引发以下错误:
预期声明结束(字符:74)
我看到许多关于在其及其参数路径中运行带空格的程序的类似问题。我尝试将上面的命令改成数百个不同的命令,并在答案中看到不同位置添加更多双引号,但没有任何效果,每次运行脚本时,都会发生以下错误之一:
预期结束声明
系统找不到指定的文件/路径(null)
未端接的弦常数
预期“)”
预期“(”
答案 0 :(得分:3)
如果你跟着this answer,你会发现你的字符串中没有双引号被转义。
来自A: Not able to launch bat file form VBScript if path contains a space
你只需要正确地转义字符串中的引号,规则是每当你想在字符串中显示一个引号加倍时。
所以该行应
WshShell.Run "CMD /C """"C:\Program Files (x86)\VideoLAN\VLC\VLC"" -vvv ""http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO=="" :sout=#file{dst=""F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4"",no-overwrite} :sout-keep""""", 0, False
哪个将作为
运行CMD /C ""C:\Program Files (x86)\VideoLAN\VLC\VLC" -vvv "http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO==" :sout=#file{dst="F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4",no-overwrite} :sout-keep""
@JosefZ在他们的answer中正确地指出原始命令有一个不必要的尾随双引号("
),所以尽管规则是正确的为了得到正确的结果,你试图逃脱的原始命令需要是正确的。我根据你的问题做了一个假设;
"我有一个命令可以正常使用命令提示符"
原始命令应该是
CMD /C ""C:\Program Files (x86)\VideoLAN\VLC\VLC" -vvv "http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO==" :sout=#file{dst="F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4",no-overwrite} :sout-keep""
使用此方法的将是
WshShell.Run "CMD /C """"C:\Program Files (x86)\VideoLAN\VLC\VLC"" -vvv ""http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO=="" :sout=#file{dst=""F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4"",no-overwrite} :sout-keep""", 0, False
并导致执行
CMD /C ""C:\Program Files (x86)\VideoLAN\VLC\VLC" -vvv "http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO==" :sout=#file{dst="F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4",no-overwrite} :sout-keep"
答案 1 :(得分:3)
您只需要正确地转义字符串中的引号即规则 是每当你想在一个字符串中显示一个引号加倍它。
但是,原始代码中仍然存在不平衡的双引号(剩余尾随"
)。
WshShell.Run "CMD /C """"C:\Program Files (x86)\VideoLAN\VLC\VLC"" -vvv ""http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO=="" :sout=#file{dst=""F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4"",no-overwrite} :sout-keep"""
这将以
运行CMD /C ""C:\Program Files (x86)\VideoLAN\VLC\VLC" -vvv "http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO==" :sout=#file{dst="F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4",no-overwrite} :sout-keep"
示例VBScript (特定的可执行文件cliparserPause.exe
用于模仿 VLC
行为):
option explicit
On Error GoTo 0
Dim strResult: strResult = Wscript.ScriptName
Dim sCmdToRun, WshShell, intReturn
' CMD /C ""D:\bat\Prog Files (x86)\cliparserPause.exe" -vvv "http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO==" :sout=#file{dst="F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4",no-overwrite} :sout-keep"
sCmdToRun = "CMD /C """"D:\bat\Prog Files (x86)\cliparserPause.exe"" -vvv ""http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO=="" :sout=#file{dst=""F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4"",no-overwrite} :sout-keep"""
strResult = strResult & vbNewLine & sCmdToRun
Set WshShell = WScript.CreateObject("WScript.Shell")
intReturn = WshShell.Run( sCmdToRun, 1, true)
strResult = strResult & vbNewLine & Cstr( intReturn )
Wscript.Echo strResult
Wscript.Quit( intReturn )
<强>输出强>:
==> CMD /C ""D:\bat\Prog Files (x86)\cliparserPause.exe" -vvv "http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO==" :sout=#file{dst="F:\\Partition C
Backup\\Downloads\\Video\\TESTING.mp4",no-overwrite} :sout-keep"
param 0 = D:\bat\Prog Files (x86)\cliparserPause.exe
param 1 = -vvv
param 2 = http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO==
param 3 = :sout=#file{dst=F:\\Partition C Backup\\Downloads\\Video\\TESTING.mp4,no-overwrite}
param 4 = :sout-keep
press any key to continue...
==> echo %errorlevel%
-1004
==> cscript //NOLOGO D:\VB_scripts\SO\43649265.vbs
43649265.vbs
CMD /C ""D:\bat\Prog Files (x86)\cliparserPause.exe" -vvv "http://www.foo.com:8085/video.mp4/playlist.m3u8?wmsAuthSign=c2VydmVyX3RpbWU9NC8yNy8yMDE3IDEyO==" :sout=#file{dst="F:\\Partition C Bac
kup\\Downloads\\Video\\TESTING.mp4",no-overwrite} :sout-keep"
-1004
==> echo %errorlevel%
-1004
cliparserPause.exe 来源:
#include "stdafx.h"
#include <wchar.h>
#include <cstdio>
#include <stdlib.h>
int main(int argc, wchar_t* argv[])
{
for (int i = 0; i < argc; ++i)
{
wprintf(L"param %d = %S\n", i, argv[i]);
}
wprintf(L"press any key to continue...");
std::getchar();
exit(-999 - argc); /* exitcode to OS = ( -1000 -supplied_paramaters_count ) */
return 0;
}