G
Guest
I am currently using the process class to successfully run .exe programs from
my VB.NET app redirecting stdin and out. This works fine when the input and
output streams are text.
I tried applying the same logic to files that are not ASCII text -- they are
PCL.
Below is the code I am using for text input. This does not work for PCL
files. I tried using the binary reader writer to no avail.
Any suggestions would be greatly appreciated!!
Thanks,
Hanika
Code:
Dim pInfo As New ProcessStartInfo
Dim timeOut As Integer = 5000
Dim filterLog As StreamWriter
With pInfo
.FileName = GetShortName(Me.mFilter)
.Arguments = Me.mFilterArgs
.WindowStyle = ProcessWindowStyle.Hidden
.CreateNoWindow = True
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
End With
Try
'Start the process.
Dim p As Process = Process.Start(pInfo)
'Write to standard Input
Dim fsr As StreamReader = New StreamReader(Me.mPath)
p.StandardInput.AutoFlush = True
p.StandardInput.Write(fsr.ReadToEnd)
fsr.Close()
p.StandardInput.Close()
'Log standard error
If p.StandardError.Peek <> -1 Then
filterLog = IO.File.CreateText(Me.mFilter & ".log")
filterLog.Write(p.StandardError.ReadToEnd)
filterLog.Close()
End If
'Write to stdOUt
Me.mFilteredData = Path.GetTempFileName
Dim fs As StreamWriter = IO.File.AppendText(Me.mFilteredData)
fs.Write(p.StandardOutput.ReadToEnd())
fs.Close()
p.WaitForExit(timeOut)
'HasExited is true if the application closed before the time-out.
If p.HasExited = False Then
'Process is still running.
'Test to see if process is hung up.
If p.Responding Then
'Process was responding; close the main window.
p.CloseMainWindow()
Else
'Process was not responding; force the process to close.
p.Kill()
End If
End If
my VB.NET app redirecting stdin and out. This works fine when the input and
output streams are text.
I tried applying the same logic to files that are not ASCII text -- they are
PCL.
Below is the code I am using for text input. This does not work for PCL
files. I tried using the binary reader writer to no avail.
Any suggestions would be greatly appreciated!!
Thanks,
Hanika
Code:
Dim pInfo As New ProcessStartInfo
Dim timeOut As Integer = 5000
Dim filterLog As StreamWriter
With pInfo
.FileName = GetShortName(Me.mFilter)
.Arguments = Me.mFilterArgs
.WindowStyle = ProcessWindowStyle.Hidden
.CreateNoWindow = True
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
End With
Try
'Start the process.
Dim p As Process = Process.Start(pInfo)
'Write to standard Input
Dim fsr As StreamReader = New StreamReader(Me.mPath)
p.StandardInput.AutoFlush = True
p.StandardInput.Write(fsr.ReadToEnd)
fsr.Close()
p.StandardInput.Close()
'Log standard error
If p.StandardError.Peek <> -1 Then
filterLog = IO.File.CreateText(Me.mFilter & ".log")
filterLog.Write(p.StandardError.ReadToEnd)
filterLog.Close()
End If
'Write to stdOUt
Me.mFilteredData = Path.GetTempFileName
Dim fs As StreamWriter = IO.File.AppendText(Me.mFilteredData)
fs.Write(p.StandardOutput.ReadToEnd())
fs.Close()
p.WaitForExit(timeOut)
'HasExited is true if the application closed before the time-out.
If p.HasExited = False Then
'Process is still running.
'Test to see if process is hung up.
If p.Responding Then
'Process was responding; close the main window.
p.CloseMainWindow()
Else
'Process was not responding; force the process to close.
p.Kill()
End If
End If