Vbscript 使用VBS调用CMD在echo处挂起

Vbscript 使用VBS调用CMD在echo处挂起,vbscript,cmd,Vbscript,Cmd,我遇到了一个奇怪的问题 我试图用vbs脚本调用cmd,但它挂起在最奇怪的地方 下面是挂起的我的cmd的oExecShell.StdOut.ReadLine: set targetDir=\\Backupstorage\Servername$\2014-11-28_12-00 if not exist \\Backupstorage\Servername$\2014-11-28_12-00 (mkdir \\Backupstorage\Servername$\2014-11-28_12-00 )

我遇到了一个奇怪的问题

我试图用vbs脚本调用cmd,但它挂起在最奇怪的地方

下面是挂起的我的cmd的oExecShell.StdOut.ReadLine:

set targetDir=\\Backupstorage\Servername$\2014-11-28_12-00
if not exist \\Backupstorage\Servername$\2014-11-28_12-00 (mkdir \\Backupstorage\Servername$\2014-11-28_12-00 ) 
Rem Works Fine
 set LogDir=\\\Backupstorage\Servername$\2014-11-28_12-00\Logs 
Rem Does not work for some strange Reason
echo "here" 
"here"
然后它挂起,杀死它的线应该是:

echo %LogDir%
echo "we have the problem"
有人有一张照片吗

下面是启动cmd的一些代码:

strAction = "C:\makeBackup_test.cmd"
Dim WshShell : Set WshShell = CreateObject("WScript.Shell")
strAction = Wshshell.expandenvironmentstrings(strAction)
Dim oExecShell : Set oExecShell = WshShell.Exec(strAction)
Do While oExecShell.Status = 0
        WScript.Sleep 100
Loop
writelog("... ExitCode is: " & oExecShell.ExitCode)
LastShellOutput = ""
Do While not(oExecShell.StdOut.AtEndOfStream)
LastShellOutput = LastShellOutput & oExecShell.StdOut.ReadLine & vbCrlf
Loop
writelog("StdOut: " & LastShellOutput) 

有人有主意吗?

用CMD/C调用int解决了这个问题。(strAction=“CMD/C:\makeBackup_test.CMD”)

直接运行批处理文件(没有VBScript包装器)时会发生什么情况?然后它就工作了,这是它的奇怪之处。我只是不明白为什么使用
strAction=“cmd/C start”“”“”和“”&Wshshell.expandenvironmentstrings(strAction)和“”
时YVBS对我有效,但在
set LogDir=\\\Backup…
中有第三个反斜杠,当在cmd中用作UNC路径时,这是不能容忍的(虽然
set
only是好的,但是可以
set
变量设置为几乎没有限制的任意字符串)最好的结果是
strAction=“cmd/C”和“&Wshshell.expandenvironmentstrings(strAction)&”
Run
方法,而不是
Exec
方法,如下所示:
Dim xReturn:xReturn=WshShell.Run(strAction,True)
。可以在运行命令终止的类型上测试
xReturn
值(如果由
×
或通过任务管理器等强制执行,程序或
&hC000013A
返回的错误代码)@JosefZ该方法需要将输出重定向到临时文件以保留它。