Vbscript 使用vb脚本检查生成执行是否成功

Vbscript 使用vb脚本检查生成执行是否成功,vbscript,cmd,build,Vbscript,Cmd,Build,我正在使用VB脚本运行一个批处理文件,它将运行一个构建 在构建之后,我想检查脚本本身的构建是否成功,即使构建成功或不成功 我怎样才能做到呢 Dim objShell Set objShell = WScript.CreateObject("WScript.Shell") objShell.Run "cmd /k cd c:\filename.bat" 我只是在使用上面的代码,它将运行一个批处理文件,该批处理文件将运行一个构建,接下来我想检查构建是否成功。 那么,我怎样才能暂停我的vb脚本一段时

我正在使用VB脚本运行一个批处理文件,它将运行一个构建

在构建之后,我想检查脚本本身的构建是否成功,即使构建成功或不成功

我怎样才能做到呢

Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "cmd /k cd c:\filename.bat"
我只是在使用上面的代码,它将运行一个批处理文件,该批处理文件将运行一个构建,接下来我想检查构建是否成功。
那么,我怎样才能暂停我的vb脚本一段时间,等待构建完成并知道结果是什么呢

请尝试一下这个示例代码:

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
'**********************************************************************************************

请尝试此示例代码:

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
'**********************************************************************************************

编辑您的问题并发布您的代码@Hackoo Dim objShell Set objShell=WScript.CreateObject(“WScript.Shell”)objShell.Run“cmd/k cd c:\filename.bat”我只是在使用上面的代码,它将运行一个批处理文件,该批处理文件将运行生成,接下来我想检查生成是否成功。那么,我怎样才能暂停我的vb脚本一段时间,等待构建完成,并知道结果是什么样的构建?不要在评论中发布其来源,而是在问题中编辑问题并发布代码@Hackoo Dim objShell Set objShell=WScript.CreateObject(“WScript.Shell”)objShell.Run“cmd/k cd c:\filename.bat”我只是在使用上面的代码,它将运行一个批处理文件,该批处理文件将运行生成,接下来我想检查生成是否成功。那么,我怎样才能暂停我的vb脚本一段时间,等待构建完成,并知道结果是什么样的构建?不是在注释中而是在问题中发布其源代码好的,我可以不使用'>'或'>>'使用vbscript读取命令提示符的内容吗。因为我想稍后在批处理文件完全执行时读取内容@Hackoo@AkashS.Did您的意思是要捕获正在运行的任何批处理文件的代码源?就像这个可以捕获任何vbscript的源代码:我不希望批处理文件的源代码运行,我希望捕获从命令promt执行的批处理文件的输出。好的,我可以在不使用vbscript的情况下读取命令提示符的内容吗。因为我想稍后在批处理文件完全执行时读取内容@Hackoo@AkashS.Did您的意思是要捕获正在运行的任何批处理文件的代码源?就像这个可以捕获任何vbscript的源代码:我不希望批处理文件的源代码运行,我希望捕获从命令promt执行的批处理文件的输出。