473,608 Members | 2,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

system.diagnost ics.process OutputDataRecei ved not quite firing

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.Standar dOutput.ReadToE nd()

however in the following example, ( inside a webservice method ), the
OutputDataRecei ved never fires:

Process p = new Process();
p.OutputDataRec eived += new
DataReceivedEve ntHandler(p_Out putDataReceived );
p.ErrorDataRece ived += new
DataReceivedEve ntHandler(p_Err orDataReceived) ;
p.StartInfo.Fil eName = @"c:\windows\sy stem32\cscript. exe";
p.StartInfo.Arg uments = @"c:\test.vb s";
p.StartInfo.Red irectStandardOu tput = true;
p.StartInfo.Red irectStandardEr ror = true;
p.StartInfo.Use ShellExecute = false;
p.StartInfo.Cre ateNoWindow = true;
p.Start();
p.WaitForExit() ;

// this works
// Process.Start(t riggerPaths);
}

void p_ErrorDataRece ived(object sender, DataReceivedEve ntArgs e) {
string s = e.Data.ToString ();
}

void p_OutputDataRec eived(object sender, DataReceivedEve ntArgs e) {
// never fires
string s = e.Data.ToString ();
}

Feb 9 '07 #1
1 10356
"ice9" <so*******@gmai l.comwrote in message
news:11******** *************@h 3g2000cwc.googl egroups.com...
>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.Standar dOutput.ReadToE nd()

however in the following example, ( inside a webservice method ), the
OutputDataRecei ved never fires:

Process p = new Process();
p.OutputDataRec eived += new
DataReceivedEve ntHandler(p_Out putDataReceived );
p.ErrorDataRece ived += new
DataReceivedEve ntHandler(p_Err orDataReceived) ;
p.StartInfo.Fil eName = @"c:\windows\sy stem32\cscript. exe";
p.StartInfo.Arg uments = @"c:\test.vb s";
p.StartInfo.Red irectStandardOu tput = true;
p.StartInfo.Red irectStandardEr ror = true;
p.StartInfo.Use ShellExecute = false;
p.StartInfo.Cre ateNoWindow = true;
p.Start();
p.WaitForExit() ;

// this works
// Process.Start(t riggerPaths);
}

void p_ErrorDataRece ived(object sender, DataReceivedEve ntArgs e) {
string s = e.Data.ToString ();
}

void p_OutputDataRec eived(object sender, DataReceivedEve ntArgs e) {
// never fires
string s = e.Data.ToString ();
}


You have to start an asynchronous read of both standarderror and standardoutput before
calling WaitForExit.
Search the docs for BeginOutputRead Line etc...

Willy.

Feb 9 '07 #2

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

Similar topics

0
4663
by: rob | last post by:
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 OutputDataReceived is not called until the DOS program is...
6
2198
by: danl | last post by:
I need to be able to execute a .bat file from a C# web application I have the following code that compliles and seems to run fine, but the bat file never does it's work =================================== System.Diagnostics.Process p = new Process() p.StartInfo.RedirectStandardOutput=false p.StartInfo.FileName = "C:\\ftp_scripts\\script.bat" p.StartInfo.UseShellExecute=true p.Start() p.WaitForExit() p.Dispose();
1
5971
by: solex | last post by:
Hello All, Hopefully someone has run into this error. I have written a class(source below) that launches a thread to monitor the StandardOutput of a System.Diagnostics.Process, in particular I am executing the find.exe program. The application works perfectly in the development environment. As soon as I execute the compiled program and start the find process I get an "Application Error". The error states that the instruction...
11
3741
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very simple batch file (echo hello world) and was trying to retrieve the standard output but every time I run the code it returns ExitCode as 1.
4
11106
by: Liverpool fan | last post by:
I have a windows application written using VB .NET that encompasses a countdown timer modal dialog. The timer is a System.Timers.Timer with an interval of 1 second. AutoReset is not set so accepts the default of True. The Elapsed event handler updates the dialog box with how long before it will close, acting as a timer itself. The dialog has a time to close property which is checked every time the Elapsed event fires. The problem I have...
0
1794
by: Daniel | last post by:
System.Diagnostics.Process.Start fails on windows server 2003 the process returns process.ExitCode == 0 but executing any process with System.Diagnostics.Process.Start on windows xp works fine. anything to do different for windows server 2003? some special permission for the process that executes another executable with System.Diagnostics.Process.Start ?? here is the code:
2
5718
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
1466
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
3068
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
8002
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8496
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8475
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...
0
6816
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...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4024
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2474
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
1
1594
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1329
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.