473,320 Members | 2,004 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,320 software developers and data experts.

system.diagnostics.process OutputDataReceived 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.StandardOutput.ReadToEnd()

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

Process p = new Process();
p.OutputDataReceived += new
DataReceivedEventHandler(p_OutputDataReceived);
p.ErrorDataReceived += new
DataReceivedEventHandler(p_ErrorDataReceived);
p.StartInfo.FileName = @"c:\windows\system32\cscript.exe";
p.StartInfo.Arguments = @"c:\test.vbs";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();

// this works
// Process.Start(triggerPaths);
}

void p_ErrorDataReceived(object sender, DataReceivedEventArgs e) {
string s = e.Data.ToString();
}

void p_OutputDataReceived(object sender, DataReceivedEventArgs e) {
// never fires
string s = e.Data.ToString();
}

Feb 9 '07 #1
1 10257
"ice9" <so*******@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.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.StandardOutput.ReadToEnd()

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

Process p = new Process();
p.OutputDataReceived += new
DataReceivedEventHandler(p_OutputDataReceived);
p.ErrorDataReceived += new
DataReceivedEventHandler(p_ErrorDataReceived);
p.StartInfo.FileName = @"c:\windows\system32\cscript.exe";
p.StartInfo.Arguments = @"c:\test.vbs";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();

// this works
// Process.Start(triggerPaths);
}

void p_ErrorDataReceived(object sender, DataReceivedEventArgs e) {
string s = e.Data.ToString();
}

void p_OutputDataReceived(object sender, DataReceivedEventArgs 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 BeginOutputReadLine etc...

Willy.

Feb 9 '07 #2

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

Similar topics

0
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...
6
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...
1
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...
11
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...
4
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...
0
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....
2
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;...
0
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;...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.