ed wrote:
Like I said, I'm pretty new to VB but I don't think this does what I'm
looking for.
From what I can tell it opens a text file with notepad in the bin
directory.
What I am looking for is a way to stream the output of a batch file
into the gui so say my batch had 2 lines
Batch files are run by the command processor (cmd.exe). In order to do
what you want, you need use Process.Start to run cmd.exe and pass it
the appropriate parameters to execute your batch file. The Process
class has a property called RedirectStandardOutput. You would set that
to True and then in your program, you would have to open the standard
output stream to get the output from the batch file.
The RedirectConsole example that Herfried posted shows how to do that.
Although his comments are in german, the code is fairly straight
forward.
Here is another example that executes a batch file and captures its
output:
Using m_Process As New Process()
With m_Process.StartInfo
.FileName = "cmd.exe"
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardOutput = True
.Arguments = "/C c:\test\test.bat"
End With
m_Process.Start()
m_Process.WaitForExit(5000)
Dim output As String = m_Process.StandardOutput.ReadLine()
While output <Nothing
TextBox1.Text &= output & vbCrLf
output = m_Process.StandardOutput.ReadLine()
End While
End Using
If the batch file has errors, they may be displayed on the
StandardError stream instead of the StandardOutput stream. Be sure to
read the docs on the RedirectStandardError property because there is
the possibility of a deadlock if you try to read both the standard
output and error streams at the same time. The docs tell how to avoid
that.
Chris