Redirecting standard output

  • Thread starter Thread starter mhmtzdmr
  • Start date Start date
M

mhmtzdmr

Hi,

I want to run an application and capture its standard output. But the
following code does not generate any output. Can anyone see something
wrong?


Public Sub RunApp(ByVal myprocess As String, ByVal param As String,
ByVal workingDir As String)

Dim p As Process = New Process()
Dim psi As New ProcessStartInfo()
psi.FileName = myprocess
psi.WorkingDirectory = workingDir
psi.Arguments = param
psi.UseShellExecute = False
psi.CreateNoWindow = True
psi.RedirectStandardOutput = True
psi.RedirectStandardInput = True
psi.RedirectStandardError = True
p.StartInfo = psi
p.Start()


AppendLine(p.StandardOutput.ReadToEnd)

p.WaitForExit()

End Sub


-----------

Then I call the sub like below.

RunApp("c:\auunitdel.exe", "-d", "")



Thanks...
 
I want to run an application and capture its standard output. But the
following code does not generate any output. Can anyone see something
wrong?
p.Start()
AppendLine(p.StandardOutput.ReadToEnd)
p.WaitForExit()

The program almost certainly /is/ creating some output - you're just not
waiting for the program to finish before reading the output that it
hasn't had time to create yet.

Swap the last two lines around, as in

p.Start()
p.WaitForExit()
AppendLine(p.StandardOutput.ReadToEnd)

HTH,
Phill W.
 
Hi,

I want to run an application and capture its standard output. But the
following code does not generate any output. Can anyone see something
wrong?


Public Sub RunApp(ByVal myprocess As String, ByVal param As String,
ByVal workingDir As String)

Dim p As Process = New Process()
Dim psi As New ProcessStartInfo()
psi.FileName = myprocess
psi.WorkingDirectory = workingDir
psi.Arguments = param
psi.UseShellExecute = False
psi.CreateNoWindow = True
psi.RedirectStandardOutput = True
psi.RedirectStandardInput = True
psi.RedirectStandardError = True
p.StartInfo = psi
p.Start()


AppendLine(p.StandardOutput.ReadToEnd)

p.WaitForExit()

End Sub


-----------

Then I call the sub like below.

RunApp("c:\auunitdel.exe", "-d", "")

I think you will have to set up a stream reader to read the output of
the process.
 
Back
Top