[Mono-list] Capturing output from Linux Command Line programs
mono-list.1.tracyanne at spamgourmet.com
mono-list.1.tracyanne at spamgourmet.com
Tue Aug 16 08:28:48 EDT 2005
> What's wrong with firing off a System.Diagnostics.Process that executes
> it, and reading the output from the "StandardOutput" stream on the
> process? You say that Process "does not seem to function as expected";
> howso?
>
> Regards,
> -= El =-
Try this,
using System;
using System.Diagnostics;
using System.IO;
class MainClass
{
public static void Main(string[] args)
{
ProcessStartInfo psi = new ProcessStartInfo("wget");
//
//change the pths to one of your choosing
//
psi.Arguments = "-m -nd --directory-prefix=/home/tracy/Downloads/test
--input-file=/home/tracy/Downloads/test/wgetlist";
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
//place the following text in a file name wgetlist
//ftp://anonymous@ftp.planetmirror.com/disks/2/mandrake/devel/cooker/i586/media/main/cdrdao-1.2.0-2mdk.i586.rpm
//
psi.UseShellExecute = false;
Process process = Process.Start(psi);
Console.WriteLine("Process Name: " + process.ProcessName);
Console.WriteLine("Process Id: " + process.Id);
Console.WriteLine("Process RedirectOutput: " +
process.StartInfo.RedirectStandardOutput);
bool retn = false;
int i = 1;
while (!retn)
{
retn = process.WaitForExit(1000);
Console.WriteLine("Application has exited: " + retn.ToString());
StreamReader sr = process.StandardOutput;
Console.WriteLine("Whatever was in standard Output: " +
sr.ReadToEnd());
i++;
}
}
}
The test program reports that RedirectStandardOutput is False, even
though I set it to true, but as there is no output from wget displayed,
I assume that stdout has been redirected. But I don't get any output,
the test program block at the line
StreamReader sr = process.StandardOutput;
Regards
Tracy Barlow
More information about the Mono-list
mailing list