Redirecting standard output

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...
 
P

Phill W.

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.
 
Z

zacks

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top