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/playl
Lankymart's answer is right:
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"""
This will run as
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"
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 )
Output:
==> 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 source:
#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;
}
If you followed this answer you would realise that none of the double quotes in your string are escaped.
From A: Not able to launch bat file form VBScript if path contains a space
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.
So the line should be
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
Which will run as
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 has rightly pointed out in their answer that the original command has an unnecessary trailing double quote ("
), so although the rule is correct to get the right result the original command you are trying to escape needs to be correct. I made an assumption based off this from your question;
"I have a command that works fine with command prompt"
The original command should have been
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""
which using this method would be
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
and result in being executed as
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"