shell - WScript.Shell 和阻塞执行?

标签 shell vbscript wsh

我正在使用 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/

相关文章:

linux - 为什么我的脚本上多了一个 0

vbscript - 检查文件是否存在并(仅当存在时)打开另一个文件(或文件夹)或运行应用程序

wsh - 获取在 Windows Script Host 中运行的 JScript 错误的行号

ruby - 如何清除 Ruby 控制台实用程序中的终端?

linux - bash 信号陷阱将覆盖其 nohup 子命令的信号?

linux - 文件监控 Bash 脚本

vbscript - wsh 是 VBScript 中的保留字吗?

javascript - 自动执行 HTTP 请求

vbscript - UFT - 随机日期

internet-explorer - VBScript 将焦点设置在 IE 中的窗口上