简体   繁体   English

如何在调用另一个函数之前等待命令行活动完成?

[英]How to wait for command line activity to finish before calling another function?

Here is my code. 这是我的代码。 We use a set of commands for our msbuild process. 我们在msbuild过程中使用了一组命令。 Depending on the environment the command and other activities varies a little bit. 根据环境的不同,命令和其他活动也会有所不同。 So, I came up with something as following. 因此,我提出了以下建议。 But, there are some commands which takes a while(1m approx) to finish. 但是,有些命令需要一段时间(大约1m)才能完成。 My script doesn't wait. 我的脚本不等。 And, MoveStagedFolders() function doesn't kick off. 并且,MoveStagedFolders()函数不会启动。 I executed this function separately and it works. 我分别执行了此功能,并且可以正常工作。 So I my problems are: 所以我的问题是:

  1. Why MoveStagedFolders() is not being called? 为什么不调用MoveStagedFolders()?
  2. How to wait until commandline activities are done. 如何等待直到命令行活动完成。

      Option Explicit Dim wshShell, environment, strBuildDirectory, strWebsiteDirectory On Error Resume Next strBuildDirectory = "someFoldersPath\\*" strWebsiteDirectory = "\\\\DestinationPath\\" environment = InputBox("Please Enter the Environment.") if Trim(environment) <> "" then Set wshShell = wscript.CreateObject("wscript.Shell") wshShell.Run "C:\\Windows\\system32\\cmd.exe" WScript.Sleep 500 wshShell.sendkeys "cd c:\\Program Files +9x86+0\\Microsoft Visual Studio 13.0\\Common7\\Tools" wshShell.sendkeys "{ENTER}" wshShell.sendkeys "vsvars32.bat" wshShell.sendkeys "{ENTER}" wshShell.sendkeys "cd c:\\working\\develop" wshShell.sendkeys "{ENTER}" wshShell.sendkeys "msbuild/t:clean" wshShell.sendkeys "{ENTER}" wshShell.sendkeys "msbuild/p:configuration=" & environment wshShell.sendkeys "{ENTER}" 'I need to wait about a minute here. if UCase(environment) = "QA" then 'Restart IIS wshShell.sendkeys "iisreset /restart localhost" wshShell.sendkeys "{ENTER}" elseif environment = "123" then 'I need to move some folders to shared folder Call MoveStagedFolders() 'Wait until the moving is done if MoveStagedFolders = true then 'MsgBox "Restarting IIS" wshShell.sendkeys "iisreset /restart devIp" wshShell.sendkeys "{ENTER}" end if end if else MsgBox "No environment was entered. Build may not succeed." end if Function MoveStagedFolders() With CreateObject("Scripting.FileSystemObject") 'Need to overwrite folders .CopyFolder strBuildDirectory, strWebsiteDirectory, true End With MoveStagedFolders = true End Function 

First, don't use SendKeys for this. 首先,请勿为此使用SendKeys Put all your commands in a batch file and call that. 将所有命令放入批处理文件中,然后调用它。

Second, you can make your batch file wait for a command to complete by using the START command, like this: 其次,可以使用START命令使批处理文件等待命令完成,如下所示:

START /WAIT MyProgram.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM