[Mono-list] Capturing output from Linux Command Line programs

mono-list.1.tracyanne at spamgourmet.com mono-list.1.tracyanne at spamgourmet.com
Mon Aug 15 20:54:59 EDT 2005


Further testing using mkisofs, leads me to believe that although output
is being redirected (where to, I don't know) but the program seems to
block at this line 

StreamReader sr = process.StandardOutput;

while process waits for output from mkisofs, I assume.

output from my test app is 

/usr/bin/mkisofs
8857
False
1


until mkisofs has completed, whereupon i get the following additional
output.


#=> 
2
#=> 




using System;
using System.Diagnostics;
using System.IO;

class MainClass
{
	public static void Main(string[] args)
	{
		ProcessStartInfo psi = new ProcessStartInfo("mkisofs");
		psi.Arguments = "-r -R -J -l -L
-o /home/tracy/cdimages/mandriva-dvd.iso /mnt/cdrom";
		psi.RedirectStandardInput = true;
		psi.RedirectStandardOutput = true;
		psi.RedirectStandardError = true;
		psi.UseShellExecute = false;
		
		
		Process process = Process.Start(psi);
		
		Console.WriteLine(process.ProcessName);
		Console.WriteLine(process.Id);
		Console.WriteLine(process.StartInfo.RedirectStandardOutput);
		
		bool retn = false;
		int i = 1;
		while (!retn)
		{
			process.StartInfo.RedirectStandardInput = true;
			process.StartInfo.RedirectStandardOutput = true;
			process.StartInfo.RedirectStandardError = true;
			retn = process.WaitForExit(1000);
			Console.WriteLine(i.ToString());
			StreamReader sr = process.StandardOutput;			
			Console.WriteLine("#=> " + sr.ReadToEnd());

			i++;
		}
	}
}


More information about the Mono-list mailing list