I am trying to determine what serial ports are available using VB.NET. When I run a batch file from the command line, it works fine. When I try to run it and capture the output, the chgport command is not recognized as shown below
I tried changing UseShellExecute to False, but it says it needs to the true to capture the output.
I tried being very specific with the paths, even using a command shell to run the chgport command. None of that made any difference.
Any thoughts on what is causing the difference between running from the command line and running in a process to capture the output?
The code snippet I'm using to capture the output:
' Fill in the com ports and file versions
Dim oProcess As New Process()
Dim oStartInfo As New ProcessStartInfo("c:\xpp_prog\ports_and_files.bat", "")
oStartInfo.UseShellExecute = False
oStartInfo.RedirectStandardOutput = True
oStartInfo.RedirectStandardError = True
oProcess.StartInfo = oStartInfo
oProcess.Start()
Dim sOutputS As String
Using oStreamReader As System.IO.StreamReader = oProcess.StandardOutput
sOutputS = oStreamReader.ReadToEnd()
End Using
Dim sOutputE As String
Using oStreamReader As System.IO.StreamReader = oProcess.StandardError
sOutputE = oStreamReader.ReadToEnd()
End Using
MsgBox(sOutputS + sOutputE)
Here is the batch file:
@echo off
cmd /c C:\Windows\System32\chgport.exe
dir c:\xpp_prog\build_*
