473,385 Members | 1,606 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,385 software developers and data experts.

Redirect lengthy application's output?

Process p = new Process();
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.StandardOutput.ReadToEnd();

This works if the application outputs very little amount of string and
exits quickly. But what if the application does a lengthy job and
outputs the progress and my C# application should be notified if the
job is progressed? Should I periodically invoke ReadToEnd() in a while
loop? Seems a waste of cpu cycles. Can't I just get notified when the
application outputs something instead? I tried to search the Internet
myself, but I couldn't find an answer.

Oct 21 '07 #1
2 1457
Sure can. The Process class has an event called OutputDataReceived that is
reaised when something is written to the redirected StandardOutput stream.

http://msdn2.microsoft.com/en-us/lib...s_members.aspx

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"Sin Jeong-hun" <ty*******@gmail.comwrote in message
news:11*********************@i38g2000prf.googlegro ups.com...
Process p = new Process();
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.Start();
p.StandardOutput.ReadToEnd();

This works if the application outputs very little amount of string and
exits quickly. But what if the application does a lengthy job and
outputs the progress and my C# application should be notified if the
job is progressed? Should I periodically invoke ReadToEnd() in a while
loop? Seems a waste of cpu cycles. Can't I just get notified when the
application outputs something instead? I tried to search the Internet
myself, but I couldn't find an answer.
Oct 21 '07 #2
Sin Jeong-hun wrote:
[...]
p.StandardOutput.ReadToEnd();

This works if the application outputs very little amount of string and
exits quickly. But what if the application does a lengthy job and
outputs the progress and my C# application should be notified if the
job is progressed? [...]
As an alternative to using the OutputDataReceived event mentioned in the
other reply, you may also just use the async methods on the
StandardOutput stream. They will work just as the async methods for
Stream do with other streams, and provide nice asynchronous access to
the data being written to the stream.

You definitely would not want to call ReadToEnd() in a while loop. It
won't complete until the stream has actually ended (is closed), which
occurs when the process exits.

Pete
Oct 21 '07 #3

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

Similar topics

1
by: Byron | last post by:
I want to take the output of a DOS console application that just streams data to the screen and redirect that output in real time into a C# application that will decode and reformat it for display....
8
by: Andreas Klemt | last post by:
Hello, I get this error Message "cannot redirect after http headers have been sent" when I do this response.redirect ("home.aspx") How can I find out with vb.net if already a http header has...
2
by: Ivan Lam | last post by:
Hi all, Thanks for reading my post!!! I am facing a problem that I cannot redirect StandartOutput and StandardInput at the same time without closing the executive. Actually, I have a...
0
by: Alison | last post by:
Hi, all, I started an application by using process and wanted to redirect the output to a textbox in VB .Net. I used newprocess.standoutput.readline since I wanted the display to be timely . The...
6
by: Cerebrus99 | last post by:
Hi all, I'm making a Windows application that does some lengthy retrieval operations from a database and possibly from a internet resource. I want to show that the operation is going on, by...
2
by: Dmitry Teslenko | last post by:
Hello! I'm using os.popen to perform lengthy operation such as building some project from source. It looks like this: def execute_and_save_output( command, out_file, err_file): import os ...
0
by: shravagiparag | last post by:
Hello, I am developing a console application to invoke gdb session and log in the communication between my application and gdb. I opened gdb as a new process and tried to redirect the input and...
18
by: Paul Lautman | last post by:
JRough wrote: What do you mean by "redirect the output to Excel"??? Excel isn't a location, it's a spreadsheet program that some (but not all users) will have on their machine. BTW, Location:...
1
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i have a console application that uses the console to display message status of my process. what's the best way (low impact) to get the messages as they are now into an email? thanks,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.