K
Kevin Hodgson
I'm trying to launch a command line utility from my VB.NET App, In my
function I create a process and launch the executable, and need to wait for
it to exit, so that the calling code can move the output file to the
userdata directory, if it's successful.
The problem I'm having is that on myProcess.WaitForExit() I get a
System.NullReferenceException, Object Reference not set to an instance of an
object.
Here's my function.
Private Function GenerateOutput(ByVal myDirectory As DirectoryInfo, ByVal
OptionFile As FileInfo, ByVal LicenceFile As FileInfo) As Boolean
'Spawn Process to execute util and wait for it to finish
Dim psi As New ProcessStartInfo((IO.Path.Combine((myDirectory.ToString),
"util.exe")), "-f " & OptionFile.Name.ToString)
psi.RedirectStandardOutput = True
psi.RedirectStandardError = True
psi.CreateNoWindow = True
psi.WorkingDirectory = myDirectory.ToString
psi.UseShellExecute = False
Dim myProcess As Process
Try
myProcess.Start(psi)
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
myProcess.WaitForExit() '**Error occurs on this line**
myProcess = Nothing
Return True
End Function
function I create a process and launch the executable, and need to wait for
it to exit, so that the calling code can move the output file to the
userdata directory, if it's successful.
The problem I'm having is that on myProcess.WaitForExit() I get a
System.NullReferenceException, Object Reference not set to an instance of an
object.
Here's my function.
Private Function GenerateOutput(ByVal myDirectory As DirectoryInfo, ByVal
OptionFile As FileInfo, ByVal LicenceFile As FileInfo) As Boolean
'Spawn Process to execute util and wait for it to finish
Dim psi As New ProcessStartInfo((IO.Path.Combine((myDirectory.ToString),
"util.exe")), "-f " & OptionFile.Name.ToString)
psi.RedirectStandardOutput = True
psi.RedirectStandardError = True
psi.CreateNoWindow = True
psi.WorkingDirectory = myDirectory.ToString
psi.UseShellExecute = False
Dim myProcess As Process
Try
myProcess.Start(psi)
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
myProcess.WaitForExit() '**Error occurs on this line**
myProcess = Nothing
Return True
End Function