我正在使用 WScript通过使用 WScript.Shell 调用外部程序来自动化一些任务。
但是,现在它不会等待外部程序完成,而是继续前进。这会导致问题,因为我有一些任务依赖于其他人先完成。
我使用的代码如下:
ZipCommand = "7za.exe a -r -y " & ZipDest & BuildLabel & ".zip " & buildSourceDir
Set wshShell = WScript.CreateObject("Wscript.Shell")
wshShell.run ZipCommand
有没有办法做到这一点,所以它会阻塞,直到 shell 执行的程序返回?
最佳答案
事实证明,while 循环严重占用 CPU 资源:P
我找到了一个更好的方法:
ZipCommand = "7za.exe a -r -y " & ZipDest & BuildLabel & ".zip " & buildSourceDir
Set wshShell = WScript.CreateObject("Wscript.Shell")
wshShell.Run ZipCommand,1,1
最后两个参数是 Show window 和 Block Execution :)
关于shell - WScript.Shell 和阻塞执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50384/