[Mono-list] Capturing output from Linux Command Line programs
Dilton McGowan II
diltonm at yahoo.com
Thu Aug 18 13:37:23 EDT 2005
Cool, odd, but cool that you found a workaround Tracy.
--- mono-list.1.tracyanne at spamgourmet.com wrote:
>
> > Dilton McGowan II diltonm at yahoo.com
> > Tue Aug 16 19:38:50 EDT 2005
> >
> > Using the code from your original post,
> substituting
> > ls for wget works. "standard" is not always
> standard.
> > IIRC, some programs output to screen memory for
> speed
> > rather than through the BIOS character IO
> subsystem.
>
>
> So I have discovered, and that was what lead to my
> confusion. The
> following code using wget does, however work. You
> will notice that I am
> reading the stream from stderr. When I do this I am
> able to retrieve
> the status information that wget normally writes to
> the console.
>
> using System;
> using System.Diagnostics;
> using System.IO;
>
> class MainClass
> {
> public static void Main(string[] args)
> {
> ProcessStartInfo psi = new ProcessStartInfo();
> psi.FileName = "/usr/bin/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 = false;
> psi.RedirectStandardOutput = false;
> 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 RedirectInput: " +
> process.StartInfo.RedirectStandardInput);
> Console.WriteLine("Process RedirectOutput: " +
> process.StartInfo.RedirectStandardOutput);
> Console.WriteLine("Process RedirectError: " +
> process.StartInfo.RedirectStandardError);
>
> Console.WriteLine("Processing");
> bool retn = false;
> while (!retn)
> {
> StreamReader sr = null;
> sr = process.StandardError;
>
> string content = sr.ReadLine();
> Console.WriteLine("Stuff my GUI application will
> use: " + content);
>
> retn = process.WaitForExit(1000);
> }
>
> Console.WriteLine("Process has exited: " +
> retn.ToString());
> process.Close();
> }
> }
>
> _______________________________________________
> Mono-list maillist - Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Mono-list
mailing list