Cong wrote:
> ...
>    public class ExternalProgram
>    {
>        public static int ExecuteProgram(string program, string arguments)
>        {
>            Process process = new Process();
>            process.StartInfo.FileName = program;
>            process.StartInfo.Arguments = arguments;
>            process.StartInfo.UseShellExecute = false;
>            process.StartInfo.RedirectStandardOutput = true;
>            process.StartInfo.RedirectStandardError = true;
>            process.StartInfo.CreateNoWindow = true;
>            process.Start();
>
>            process.WaitForExit();
I don't see how this can work at all.  If you look at the documentation 
for the Process.StandardOutput property (for .Net 1.1), you'll see an 
example that shows that this will deadlock.  The online docs at 
http://msdn2.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
 
don't have the example anymore, but still says the same thing about this 
deadlocking.

In any event, you're misunderstanding how the 
process.StartInfo.RedirectStandardOutput mechanism works and similar.  
Normally the process will write to the console.  If you set this 
property, then the process class will create its own Stream (probably a 
MemoryStream, but it doesn't matter and you shouldn't care).  It will 
then create a StreamWriter from this stream, and passes that to the 
subprocess as the standard output.  It will also create a StreamReader 
from this stream, and store in the process.StandardOutput property.  
It's then your job to use that StreamReader to read the output and put 
it wherever you want.  In other words, the Process class won't do the 
redirection for you.  It just gives you the streams you need so that you 
can do the redirection.

Gary


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to