如何以编程方式等待 Shell 命令完成运行? [英] How To Programmatically Wait For Shell Command To Finish Running?

查看:15
本文介绍了如何以编程方式等待 Shell 命令完成运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在这样的程序中发送电子邮件:

I am sending emails in a program like so:

Call Shell(smtpPath, emailInput...)

这很好用,除非我调用函数两次,函数第一次运行,调用shell命令,然后函数再次运行,再次调用shell命令,但是第一个shell命令没有完成,所以出现错误,因为第二个 shell 命令尝试使用与第一个命令相同的 smtp 文件(仍在使用中).

This works great, except if I call the function twice, the function runs the first time, calls the shell command, then the function runs again, and calls the shell command again, but the first shell command is not completed, so there is an error because the second shell command is trying to use the same smtp file as the first one (that is still in use).

如何让函数等到 shell 命令完成运行?

How can I make the function wait until the shell command has finished running?

附录:或者有什么方法可以查看文件是否正在被使用,如果是,休眠它,然后再试一次?

Addendum: Or is there a way I can see if the file is being used, and if it is, sleep it, then try again?

推荐答案

你可以使用 WScript.Shell,它是 运行 方法:

You could use WScript.Shell, and it's run method:

Set objShell = CreateObject("WScript.Shell")
result = objShell.Run(smtpPath & " " & emailInput, 0, true)

这篇关于如何以编程方式等待 Shell 命令完成运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆