[Mono-list] System.Diagnostics.Process.StartInfo.Arguments

Fred Patterson fpatterson at novell.com
Tue Sep 1 12:31:53 EDT 2009


Chris,
 
I was able to fix it. You got me started down the right path.
I still couldn't get the argument variable to work with the 1>output.log, however, I was able to work around it.
The below code creates a file called output.log in the current path.
 
Thanks again.
 
 
                            System.Diagnostics.Process export = new System.Diagnostics.Process();
                            export.EnableRaisingEvents = false;
                            export.StartInfo.RedirectStandardOutput = true;
                            export.StartInfo.RedirectStandardError = true;
                            export.StartInfo.UseShellExecute = false;
                            export.StartInfo.FileName = "/bin/sh";
                            export.StartInfo.Arguments = "discover.sh";
 
                            export.Start();
 
                            export.WaitForExit();
                            if (0 != export.ExitCode) Console.WriteLine("Error");
 
                            TextWriter output = new StreamWriter("output.log");
                            output.WriteLine(export.StandardOutput.ReadToEnd());
                            output.Close();
 
 
 
 

>>> Chris Howie <cdhowie at gmail.com> 9/1/2009 8:58 AM >>>
On Tue, Sep 1, 2009 at 10:52 AM, Pat55<fpatterson at novell.com> wrote:
> I am trying to start a bash script using the Process class.
> The arguments is not working. The script run, but I want to be able to
> redirect the standard output to a file.
>
> Here is the code:
>
> System.Diagnostics.Process export = new System.Diagnostics.Process();
> export.EnableRaisingEvents = false;
> export.StartInfo.FileName = "/tool/find.sh";
> export.StartInfo.Arguments = "1>export.log";
> export.Start();
> export.WaitForExit();
> if (0 != export.ExitCode) Console.WriteLine("Error");

Try:

export.StartInfo.FileName = "/bin/sh";
export.StartInfo.Arguments = "/tool/find.sh 1>export.log";

> The find.sh script runs just fine by itself with the argument.
> The script will run with the application, but it does not push the output to
> a file with the argument specified.

That's because you are passing the argument to find.sh, which doesn't
understand redirection.  The shell is what does redirection, so you
must run the shell explicitly.

-- 
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-list/attachments/20090901/93d76ec7/attachment.html 


More information about the Mono-list mailing list