[Mono-dev] excute linux command under mono C#
Duane Wandless
duane at wandless.net
Mon May 16 09:11:25 EDT 2011
Here is a class that I use to execute linux commands:
internal int Execute(string exe, string args)
{
ProcessStartInfo oInfo = new ProcessStartInfo(exe, args);
oInfo.UseShellExecute = false;
oInfo.CreateNoWindow = true;
oInfo.RedirectStandardOutput = true;
oInfo.RedirectStandardError = true;
StreamReader srOutput = null;
StreamReader srError = null;
Process proc = System.Diagnostics.Process.Start(oInfo);
proc.WaitForExit();
srOutput = proc.StandardOutput;
StandardOutput = srOutput.ReadToEnd();
srError = proc.StandardError;
StandardError = srError.ReadToEnd();
int exitCode = proc.ExitCode;
proc.Close();
return exitCode;
}
internal string StandardOutput
{
get;
private set;
}
internal string StandardError
{
get;
private set;
}
}
On Mon, May 16, 2011 at 8:05 AM, harmeets <harmeet.singh at onebcg.com> wrote:
> I tried this solution for executing linux command from asp.netapplication.
> It is not working for me. We just want to move files from one folder to
> another. My code is
> string cmd = "/bin/cp -rp
> /usr/local/lib/xsp/test/2.0/projectname/invoices/
> /usr/local/lib/xsp/test/2.0/projectname/testupload/";
> System.Diagnostics.Process proc = new System.Diagnostics.Process();
> proc.StartInfo.FileName = "bash"; //here
> proc.StartInfo.Arguments ="-c ' " + cmd + " ' "; ////??????
> proc.StartInfo.UseShellExecute = false; ///????
>
>
> We cannot use File.Copy because destination folder is mounted with Amazon
> S3. While copying files it shows error folder not found. We will have to
> copy files using command line.
>
> --
> View this message in context:
> http://mono.1490590.n4.nabble.com/excute-linux-command-under-mono-C-tp1533563p3526039.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20110516/cfee7097/attachment.html
More information about the Mono-devel-list
mailing list