[MonoDevelop] How to run a bash terminal command from Mono/MonoDevelop in Linux?

Ian Norton ian.norton-badrul at thales-esecurity.com
Tue Jul 29 19:31:02 UTC 2014


Are you trying to run a shell script? If the thing isn't a script then run that instead of bash

On 29 July 2014 18:57:09 BST, Hari <phariparam at gmail.com> wrote:
>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/96c13f2e/attachment.html>


More information about the Monodevelop-list mailing list