Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 12th, 2005, 07:14 PM
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Redirecting StandardOutput: blocks until exit

I am writing a C# program that launches a program as a new process and tracks its progress by reading from StandardOutput for status reports. I have StandardOutput of that process redirected to a local StreamReader which gets text from it line-at-a-time.

My problem: the ReadLine call to the StreamReader blocks until the process has exited, then spits out all of the lines the program printed all at once. Happens with just using Read to get the first character as well. What would cause this? Is there some option I can set to get it to give me the output while it executes?

Code:
//start the rainbow execution engine
ProcessStartInfo psi = new ProcessStartInfo(
System.Environment.CurrentDirectory+"\\rtgen.exe" );
psi.WorkingDirectory = "data";
psi.UseShellExecute = false;
psi.CreateNoWindow  = true;
psi.RedirectStandardInput  = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError  = true;
extProcess = Process.Start(psi);

StreamWriter input  = extProcess.StandardInput;
StreamReader output = extProcess.StandardOutput;
StreamReader error  = extProcess.StandardError;

//blocks here w/ no output until program exit
while( (line = output.ReadLine()) != null )
{
...
}
Any ideas?

 
Old April 17th, 2005, 05:33 PM
Authorized User
 
Join Date: Jun 2003
Location: Glendale, California, USA.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to HuhOiC
Default

You can try a multithreaded app or see if there is an asynchronous call to readLine. Just another option if you haven't tried it already...

RAyRAy
Huh O i C

Program or Be Programmed!!!
 
Old April 20th, 2005, 09:58 AM
Friend of Wrox
 
Join Date: Jul 2004
Location: Tehran, , Iran.
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi there,
http://www.codeproject.com/csharp/LaunchProcess.asp
HtH.:)

_____________
Mehdi.
software student.
 
Old June 26th, 2008, 05:08 AM
Registered User
 
Join Date: Jun 2008
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi!

The link above doesn't exist anymore.
Does anyone know a solution to this problem with communication between two processes through ones standardout and -in?

 
Old June 26th, 2008, 05:17 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The article is still available via the Wayback Machine internet archive.

http://web.archive.org/web/200502070...nchProcess.asp


/- Sam Judson : Wrox Technical Editor -/




Similar Threads
Thread Thread Starter Forum Replies Last Post
Building Blocks terry s Dreamweaver (all versions) 1 August 16th, 2005 02:42 PM
The 7 application blocks EricJ General .NET 0 June 30th, 2005 06:57 AM
buildng blocks terry s Dreamweaver (all versions) 11 January 24th, 2005 02:57 PM
Building Blocks terry s Dreamweaver (all versions) 1 January 12th, 2005 02:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.