运行空格过多的程序 [英] Run programs with too many spaces
问题描述
我有一个在命令提示符下工作正常的命令:
I have a command that works fine with command prompt:
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
来返回错误级别.
Here I need CMD /C
to return the errorlevel.
这就是我尝试使用 Run
方法在 VBScript 中运行它的方式:
That's how I tried to run this in VBScript using Run
method:
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)
Expected end of statement (Char: 74)
我看到许多关于运行程序及其参数路径中带有空格的类似问题.我尝试将上述命令更改为数百个不同的命令,并在不同位置添加更多双引号,如我在答案中看到的那样,但没有任何效果,每次运行脚本时,都会发生以下错误之一:
I saw many similar questions about running programs with spaces in its and its parameters' paths. I tried changing above command into hundreds of different commands with adding more double quotation marks into different positions as I saw in answers, but nothing worked and everytime I ran the script, one of the following errors occured:
预期的语句结束
系统找不到指定的文件/路径(空)
未终止的字符串常量
应为)"
应为("
Expected end of statement
The system cannot find the file/path specified (null)
Unterminated string constant
Expected ")"
Expected "("
推荐答案
Lankymart 的回答是正确的:
你只需要正确地转义字符串中的引号,规则是每当您想在字符串中显示引号时将其加倍.
You just need to escape the quotes in the string correctly, the rule is whenever you want to show a quote in a string double it.
但是,您在原始代码中仍然有不平衡的双引号(多余的尾随 "
).
However, you still have unbalanced double quotes in the original code (a surplus trailing "
).
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
行为):>
Sample VBScript (a particular executable cliparserPause.exe
is used to mimic VLC
behaviour):
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;
}
这篇关于运行空格过多的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!