如何在 vb 程序中读取批处理文件的输出



提前致谢 我只想知道是否有办法从 vb.net 程序中正在运行的批处理文件中读取输出。谢谢!

正如上面的一位评论者提到的,您可以在 VB.NET 程序中的 shell 中运行批处理文件,然后读取定向输出。我在以前的项目中完全做到了这一点。

下面是一个代码片段,显示了如何做到这一点:

Dim outputFile As String = """" & Path.GetTempFileName & """"
Dim batchCommand As String = """C:PathToMyFile.bat"">" & outputFile
Dim cmdProcess As New Process
With cmdProcess
    .StartInfo = New ProcessStartInfo("cmd.exe", "/C " & batchCommand)
    With .StartInfo
        .CreateNoWindow = True
        .UseShellExecute = False
    End With
    .Start()
    .WaitForExit()
End With
' This is the output from the batch file.
Dim batchOutput As String = My.Computer.FileSystem.ReadAllText(outputFile)

最新更新