473,769 Members | 3,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process & OutputDataRecei ved Handler

rob
Hello,

I have a DOS program that I need to execute from a WinForm application.
This DOS program will take a long time to execute. During execution it
prints out messages. While the DOS program is still running I want to
catch these messages and display them to the user. I managed to create
the process and redirect the output. The problem I am having is that
the even handler for OutputDataRecei ved is not called until the DOS
program is finished. Once it is finished the handler gets called for
each line. My question is why does it not get called right after each
line is printed? What am I doing wrong.

Bellow is a sample code. The DOS program prints out one line (with \n")
of random numbers every every 500ms. Proc is a function that is called
when I press a button on the WinForm.

StringBuilder Output;
static int numOutputLines= 0;
private void Proc()
{
Process p = new Process();
p.StartInfo.Use ShellExecute = false;
p.StartInfo.Red irectStandardOu tput = true;
output.Output = new StringBuilder(" ");
p.OutputDataRec eived += new
DataReceivedEve ntHandler(Outpu tHandler);

p.StartInfo.Fil eName = @"randomNum.exe ";
p.StartInfo.Cre ateNoWindow = true;
p.Start();

p.BeginOutputRe adLine();
while (true)
{
string s;
s = "";
int n;

//Shows empty string until process is finished
//When process is finished it shows all lines.
s = Output.ToString ();
MessageBox.Show (s, "result");
}
p.Close();
}

private void OutputHandler(o bject sendingProcess,
DataReceivedEve ntArgs outLine)
{
//This event handler is not called until process is finished.
//When process is finished it gets called once for each line
if (!String.IsNull OrEmpty(outLine .Data))
{
numOutputLines+ +;
Output.Append(E nvironment.NewL ine +
"[" + numOutputLines. ToString() + "] - " + outLine.Data);
}
}

Regards,
Rob

Nov 17 '05 #1
0 4681

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

Similar topics

1
318
by: SnakeS | last post by:
Hi, I want say if exist an Event that find out when a process has start. For example with task manager, when a new process has start , it come update into list. Thanks.
3
1399
by: Steve B. | last post by:
Hi, I'm written a Web Service that encapsulate the call to a command line application. The command line application is run using Process.Start, and I'd like to get both standard ouput and standard error to create a log. After some searches, I finally wrote this part of code : public class MyClass {
5
11407
by: Mikko Nylén | last post by:
Hi!, I'm trying to read the output of an process as it gets executed and append the output to a RichTextBox. However, I have a little problem: the process I'm trying to execute is a Python script, which uses the time.sleep() to sleep for a specified amount of time. This (the use of time.sleep()) seems to have the side effect of the output not being added to the RichTextBox until the process has finished, which it won't do as the...
2
5738
by: Lyon | last post by:
Here is a part of my code: internal bool Excute(string input) { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = this.filePathToExcute; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true;
0
1477
by: Lyon | last post by:
Here is a part of my code: internal bool Excute(string input) { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = this.filePathToExcute; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true;
1
10398
by: ice9 | last post by:
I seem to be missing something in this straightforward example.. but i have a vbs file that is now simplified to one line: Wscript.Echo "test" When i run the process, i'd like output to be returned asynchronously since i will be running this script many times with differetn parameters and collecting return strings. my return "test" text actually work in synchronous mode: process.StandardOutput.ReadToEnd()
1
3089
by: lapucca | last post by:
Hi, I'm using VS 2005, ,.net 2 for C# windows application. I'm using Process to run a C application and redirecting its standard output so I can read it with StreamReader.ReadToEnd. It's only reading the 1st 5 lines or so when there is about 100 lines of data. I also tried using the Process.BeginOutputReadlin and a DataReceivedEvntHandler to gather output but I also only get about 5 lines of the data. There seems to be a buffer...
0
1295
by: =?Utf-8?B?UHVjY2E=?= | last post by:
I Have the following in my own library project and I call it from my C# application twice each time to get Unix group account information and user account information. But it would return different number of records (lines of data read), sometimes 0 records without any of my message, and there doesn't seem to be a pattern to be found. Can someone have a look and see if any of my code could possbly cause this? Thanks. static...
3
1731
by: =?Utf-8?B?YV93YWhvbw==?= | last post by:
I work in a group that uses a variety of third party tools to control an embedded system. I need to integrate the functionality of these tools (mostly command prompt) into a single interface. I followed the examples on MSDN and other sites to create a class that spawns a System.Diagnostics.Process with re-directed StdIn, StdOut, and StdErr. I read the user input from a textbox and write the output to another textbox. This approach...
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10051
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8879
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3571
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.