473,395 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Redirecting standard output

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

Sep 27 '06 #1
3 1585
mh******@gmail.com wrote:
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.
Sep 27 '06 #2
Phill,

I have tried that but still does not work.

Phill W. yazdi:
mh******@gmail.com wrote:
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.
Sep 27 '06 #3

mh******@gmail.com wrote:
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.

Sep 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: m_schellens | last post by:
I want to spawn an external program from my C++ app. And I want to get the standard and error output from the spawned program. Spawning is done in C++ with the int system(const char *s) ...
15
by: Matt Burland | last post by:
I'm having a problem with redirecting the StandardOutput of a process that I use to run a DOS program in my application. The problem is that I when I start my process (which I do in a separate...
5
by: vijaynats | last post by:
Hi I created a windows app to run a dos batch file (which takes around 5mins to complete and generates lots of output messages on the console in the meantime)and i used RedirectStandardOuput to...
5
by: Markus S. | last post by:
Hello, I have a problem with a DOS EXE that is called by a .Net Winforms application. I need to redirect the console output into a textbox, but this should happen in real time, so when new...
1
by: rubikzube* | last post by:
I am attempting to place a call to make via System.Diagnostics.Process using the sample code below. If I comment out the two problem lines indicated, then the code runs smoothly and make performs...
3
by: Jan Danielsson | last post by:
Hello, I thought I'd write a program to collect information from pf (packet filter) and insert it into a postgresql database for review on a web page. First I checked if this has been done already,...
3
by: Sudesh | last post by:
Hi, I am a newbie to C# and Im trying to redirect standard input, output and error of a console program written in C (MS VC 6.0) to a textbox on a form. The code for the redirecting looks like...
8
by: Morpheus | last post by:
I am trying to test a function that outputs text to the standard output, presumably using a cout call. I do not have access to the source, but need to test the output. Is this possible? I can...
1
by: pp4175 | last post by:
Hello Everyone, I am currently working on writing a GUI wrapper for a Menu driven DOS Program. What I was looking on doing is redirecting stdout/stdin to a stream and read/write similar to a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.