[MonoDevelop] How to run a bash terminal command from Mono/MonoDevelop in Linux?
Hari
phariparam at gmail.com
Tue Jul 29 17:57:09 UTC 2014
Thanks Ian.
Your code is working fine in my system. In my code I am trying to invoke
the linux binary directly and trying to pass an argument. But its not
working. I think I need to use a script and invoke the binary.
Regards
Hari
On Tue, Jul 29, 2014 at 12:38 PM, Ian Norton <
ian.norton-badrul at thales-esecurity.com> wrote:
> This works for me:
>
>
> using System;
> using System.Diagnostics;
>
> static class Test {
> public static void Main(string[] args) {
> Process proc = new Process();
> proc.StartInfo.FileName = "/bin/bash";
> proc.StartInfo.Arguments = "/home/inb/foo.sh hello";
> proc.StartInfo.UseShellExecute = false;
> proc.StartInfo.RedirectStandardError = true;
> proc.StartInfo.RedirectStandardInput = true;
> proc.StartInfo.RedirectStandardOutput = true;
> proc.Start();
>
> var output = proc.StandardOutput.ReadToEnd();
>
> Console.WriteLine(output);
> }
> }
> // end
>
>
> My foo.sh script looks like:
>
>
>
> #!/bin/bash
>
> echo "$@"
> ##### end
>
>
>
> Ian
>
> On Tue, Jul 29, 2014 at 06:22:06PM +0100, Ian Norton wrote:
> > What platform?
> >
> > On 29 July 2014 18:07:32 BST, Hari <phariparam at gmail.com> wrote:
> >
> > I want to run the following bash command programmatically using C# and
> > MonoDevelop and store the output to a variable.
> >
> > A
> >
> > ./TestApp A --H
> >
> > A
> >
> > My MonoDevelop/C# A code is as follows:
> >
> > A
> >
> > Process proc = new Process();
> >
> > proc.StartInfo.FileName = "/bin/bash";
> >
> > proc.StartInfo.Arguments = "./usr/mono/TestApp --H";
> >
> > proc.StartInfo.UseShellExecute = false;
> >
> > proc.StartInfo.RedirectStandardErrort = true;
> >
> > proc.StartInfo.RedirectStandardInput = true;
> >
> > proc.StartInfo.RedirectStandardOutput = true;
> >
> > proc.Start();
> >
> > string value = proc.RedirectStandardOutput.ReadToEnd()
> >
> > A
> >
> > A
> >
> > A The below line displaying the error
> > a**System.InvalidOperationException: No process is associated with this
> > object
> >
> > A
> >
> > Process proc = new Process();
> >
> > A
> >
> > Thank You
> >
> > A
>
> > _______________________________________________
> > Monodevelop-list mailing list
> > Monodevelop-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/monodevelop-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/monodevelop-list/attachments/20140729/dd57914c/attachment.html>
More information about the Monodevelop-list
mailing list