【发布时间】:2014-10-22 12:57:26
【问题描述】:
这是我的代码。我们为我们的 msbuild 进程使用了一组命令。根据环境的不同,命令和其他活动会有所不同。所以,我想出了如下的东西。但是,有些命令需要一段时间(大约 1m)才能完成。我的脚本不等待。而且,MoveStagedFolders() 函数不会启动。我单独执行了这个函数,它可以工作。所以我的问题是:
- 为什么没有调用 MoveStagedFolders()?
-
如何等到命令行活动完成。
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
【问题讨论】:
-
我不认为
SendKeys是您的最佳选择。您可以将所有命令放在BAT文件中并从您的VBScript 调用该批处理文件吗?如果您使用Run函数调用它并将True作为第三个参数传递,您的VBScript 将等待批处理文件完成后再继续。 -
我知道这不是最佳选择。我当然试一试。感谢您的快速回答
标签: vb.net powershell batch-file command-line vbscript