0

thanks in advance i just want to know if theres a way to read the output from a running batch file in a vb.net program. Thanks!

John
  • 23
  • 5

1 Answers1

0

As one commenter above mentions, you can run the batch file in a shell within your VB.NET program and then read the directed output. I have done this exactly in previous project.

Here is a code snippet which shows how you can do it:

Dim outputFile As String = """" & Path.GetTempFileName & """"
Dim batchCommand As String = """C:\Path\To\MyFile.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)
Jason Faulkner
  • 6,378
  • 2
  • 28
  • 33