Click here to Skip to main content
15,904,351 members
Home / Discussions / C#
   

C#

 
GeneralRe: Repost Pin
Pete O'Hanlon26-Dec-10 23:49
mvePete O'Hanlon26-Dec-10 23:49 
GeneralRe: Repost Pin
#realJSOP27-Dec-10 1:28
professional#realJSOP27-Dec-10 1:28 
GeneralRe: Repost Pin
thatraja27-Dec-10 8:08
professionalthatraja27-Dec-10 8:08 
GeneralRe: Repost Pin
Pete O'Hanlon27-Dec-10 9:34
mvePete O'Hanlon27-Dec-10 9:34 
GeneralRe: Repost Pin
Keith Barrow28-Dec-10 1:40
professionalKeith Barrow28-Dec-10 1:40 
Questionmodify XmlDictionaryReaderQuotas Pin
abbd26-Dec-10 5:24
abbd26-Dec-10 5:24 
AnswerRe: modify XmlDictionaryReaderQuotas Pin
Henry Minute26-Dec-10 6:11
Henry Minute26-Dec-10 6:11 
AnswerRe: modify XmlDictionaryReaderQuotas Pin
Keith Barrow26-Dec-10 6:11
professionalKeith Barrow26-Dec-10 6:11 
QuestionRe: modify XmlDictionaryReaderQuotas Pin
abbd26-Dec-10 6:53
abbd26-Dec-10 6:53 
AnswerRe: modify XmlDictionaryReaderQuotas Pin
Keith Barrow26-Dec-10 7:08
professionalKeith Barrow26-Dec-10 7:08 
Questionmodify XmlDictionaryReaderQuotas Pin
abbd26-Dec-10 7:19
abbd26-Dec-10 7:19 
QuestionRe: modify XmlDictionaryReaderQuotas Pin
Keith Barrow26-Dec-10 7:27
professionalKeith Barrow26-Dec-10 7:27 
QuestionRe: modify XmlDictionaryReaderQuotas Pin
abbd26-Dec-10 7:30
abbd26-Dec-10 7:30 
AnswerRe: modify XmlDictionaryReaderQuotas Pin
Keith Barrow26-Dec-10 7:59
professionalKeith Barrow26-Dec-10 7:59 
QuestionRe: modify XmlDictionaryReaderQuotas Pin
abbd26-Dec-10 8:04
abbd26-Dec-10 8:04 
QuestionRe: modify XmlDictionaryReaderQuotas Pin
abbd26-Dec-10 23:18
abbd26-Dec-10 23:18 
QuestionRedirecting standard output of an application Pin
TcachTcachTcach25-Dec-10 21:36
TcachTcachTcach25-Dec-10 21:36 
AnswerRe: Redirecting standard output of an application Pin
Abhinav S25-Dec-10 23:18
Abhinav S25-Dec-10 23:18 
GeneralRe: Redirecting standard output of an application Pin
TcachTcachTcach26-Dec-10 0:26
TcachTcachTcach26-Dec-10 0:26 
AnswerRe: Redirecting standard output of an application Pin
Luc Pattyn26-Dec-10 1:57
sitebuilderLuc Pattyn26-Dec-10 1:57 
GeneralRe: Redirecting standard output of an application Pin
TcachTcachTcach26-Dec-10 2:32
TcachTcachTcach26-Dec-10 2:32 
AnswerRe: Redirecting standard output of an application Pin
Luc Pattyn26-Dec-10 3:02
sitebuilderLuc Pattyn26-Dec-10 3:02 
This is a first draft, I did not test it:

bool stdReading;
StreamReader stdout;
StreamReader stderr;

public void LaunchProcess() {
	ProcessStartInfo psi=new ProcessStartInfo();
	psi....
	log("Starting process");
	Process p=Process.Start(psi);
	stdout=p.StandardOutput;
	stderr=p.StandardError;
	stdReading=true;
	Thread outThread=new Thread(new ThreadStart(outReader));
	outThread.Start();
	Thread errThread=new Thread(new ThreadStart(errReader));
	errThread.Start();
	p.WaitForExit();
	log("Process is done");
	Thread.Sleep(300);  // allow some time for streams to settle
	stdReading=false;
	errThread.Join(300);
	outThread.Join(300);
	log("Reading streams in done");
}
public void outReader() {
	int DIM=1024;
	char[] buf=new char[DIM];
	while (stdReading) {
		int count=stdout.Read(buf, 0, DIM);
		// now process count characters in buf
		string s=new string(buf, 0, count);
		...
	}
}
public void errReader() {
	int DIM=1024;
	char[] buf=new char[DIM];
	while (stdReading) {
		int count=stdout.Read(buf, 0, DIM);
		// now process count characters in buf
		string s=new string(buf, 0, count);
		...
	}
}


Notes:
1. you may want to decrease DIM to get the output sooner when lines are short;
2. you may want to set Thread.IsBackground true so the threads don't prevent app termination.

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Season's Greetings to all CPians.


modified on Sunday, December 26, 2010 9:30 AM

GeneralRe: Redirecting standard output of an application Pin
TcachTcachTcach26-Dec-10 3:47
TcachTcachTcach26-Dec-10 3:47 
GeneralRe: Redirecting standard output of an application Pin
Luc Pattyn26-Dec-10 3:55
sitebuilderLuc Pattyn26-Dec-10 3:55 
AnswerRe: Redirecting standard output of an application Pin
PIEBALDconsult26-Dec-10 4:56
mvePIEBALDconsult26-Dec-10 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.