[Mono-list] StandardOutput rediresd

Madars Vitolins madars.vitolins at gmail.com
Sun Mar 18 17:29:58 EDT 2007


Hi,

This works (found somewhere in google):


       protected String ShellExec(
                String cmd,
                String path,
                String parms,
                out int exit_code)
        {
            System.Diagnostics.ProcessStartInfo psi = new
System.Diagnostics.ProcessStartInfo(
                     path + cmd, parms);
            psi.RedirectStandardOutput = true;
            psi.UseShellExecute = false;

            System.Diagnostics.Process p = System.Diagnostics.Process.Start
(psi);
            string tool_output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            exit_code = p.ExitCode;
            return tool_output;
        }


Thanks,
Madars.


On 3/18/07, PChot <pchott at gmail.com> wrote:
>
> hi all
>
> i'm trying to call simple "ls" proces in linux. In than want somehot to
> redirect output to string. T tried many options bus seems that none worked.
> Here is some code that i used and it doesnt work.
>
> System.Diagnostics.Process Process3;
> Process3 = new System.Diagnostics.Process();
> Process3.StartInfo.UseShellExecute = false;
> Process3.StartInfo.RedirectStandardOutput = true;
> Process3 = System.Diagnostics.Process.Start ("ls -lah");
>
> string output = Process3.StandardOutput.ReadToEnd();
> Process3.WaitForExit();
> Process3.Close();
>
>
> Does even work Output redirect in mono? What did i do wrong?
>
> Thx for answer,
>
> PChott
>
> --
> Macs are for those who don't want to know why their computer works.
> Linux is for those who want to know why their computer works.
> DOS is for those who want to know why their computer doesn't work.
> Windows is for those who don't want to know why their computer doesn't
> work.
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20070318/e9f1150e/attachment-0001.html 


More information about the Mono-list mailing list