Click here to Skip to main content
15,897,113 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Redirecting standard output of an application Pin
TcachTcachTcach27-Dec-10 23:12
TcachTcachTcach27-Dec-10 23:12 
QuestionWeak reference and garbage collection Pin
thomus0724-Dec-10 22:24
thomus0724-Dec-10 22:24 
AnswerRe: Weak reference and garbage collection Pin
#realJSOP25-Dec-10 0:35
professional#realJSOP25-Dec-10 0:35 
AnswerRe: Weak reference and garbage collection Pin
SledgeHammer0125-Dec-10 7:27
SledgeHammer0125-Dec-10 7:27 
GeneralRe: Weak reference and garbage collection Pin
thomus0725-Dec-10 19:03
thomus0725-Dec-10 19:03 
AnswerRe: Weak reference and garbage collection Pin
Pete O'Hanlon25-Dec-10 8:41
mvePete O'Hanlon25-Dec-10 8:41 
GeneralRe: Weak reference and garbage collection Pin
thomus0725-Dec-10 19:06
thomus0725-Dec-10 19:06 
AnswerRe: Weak reference and garbage collection Pin
_Erik_27-Dec-10 2:46
_Erik_27-Dec-10 2:46 
AnswerRe: Weak reference and garbage collection Pin
jschell27-Dec-10 8:12
jschell27-Dec-10 8:12 
QuestionAnswer this question Pin
mohammed alshaweesh24-Dec-10 4:23
mohammed alshaweesh24-Dec-10 4:23 
JokeRe: Answer this question PinPopular
PIEBALDconsult24-Dec-10 4:31
mvePIEBALDconsult24-Dec-10 4:31 
GeneralRe: Answer this question Pin
OriginalGriff24-Dec-10 4:45
mveOriginalGriff24-Dec-10 4:45 
GeneralRe: Answer this question Pin
Ramkumar_S24-Dec-10 19:56
Ramkumar_S24-Dec-10 19:56 
JokeRe: Answer this question Pin
Hiren solanki24-Dec-10 21:14
Hiren solanki24-Dec-10 21:14 

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.