我正在使用VB脚本运行批处理文件,该文件将运行构建。
构建之后,我想检查构建是否成功或脚本本身是否成功,即使构建成功或不成功。
我怎样才能实现它?
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /k cd c:\filename.bat"
我只是使用上面的代码,它将运行一个将运行构建的批处理文件,接下来我想检查构建是成功还是不成功。 那么如何暂停我的vb脚本一段时间并等待构建完成并知道结果是什么
答案 0 :(得分:0)
尝试使用此示例代码:
Option Explicit
Dim BatchFile,strText
strText = "@echo off & echo Hello World. & TimeOut /T 5 & exit"
BatchFile = "filename.bat"
Call Create_BatchFile(strText,BatchFile)
wscript.echo "We execute the batch file in hidden mode !" & vbcr & "Just clic Ok button to run it !"
Call Run(BatchFile,0,True)
wscript.echo "We execute the batch file in normal mode !" & vbcr & "Just clic Ok button to run it !"
Call Run(BatchFile,1,True)
'**********************************************************************************************
Function Run(StrCmd,Console,bWaitOnReturn)
Dim ws,MyCmd,Result
Set ws = CreateObject("wscript.Shell")
'A value of 0 to hide the MS-DOS console
If Console = 0 Then
MyCmd = "CMD /C " & StrCmd & ""
Result = ws.run(MyCmd,Console,bWaitOnReturn)
If Result = 0 Then
MsgBox "Success"
Else
MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
End If
End If
'A value of 1 to show the MS-DOS console
If Console = 1 Then
MyCmd = "CMD /K " & StrCmd & ""
Result = ws.run(MyCmd,Console,bWaitOnReturn)
If Result = 0 Then
MsgBox "Success"
Else
MsgBox "An unknown error has occurred!",16,"An unknown error has occurred!"
End If
End If
Run = Result
End Function
'**********************************************************************************************
Sub Create_BatchFile(strText,BatchFile)
Const ForWriting = 2
Dim fso,ts
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(BatchFile,ForWriting,True)
ts.WriteLine strText
ts.Close
End Sub
'**********************************************************************************************