[Gtk-sharp-list] Executing Shell commands

Matt Guo matt at mattguo.com
Sun Jun 7 16:55:54 EDT 2009

Hey, Zaizeku,

The "rm" is the command, and the "-r /home/zaizeku/Desktop/test.txt"
is the arguments.

So following code shall be work:

pipes.StartInfo.FileName = "rm";
pipes.StartInfo.Arguments = "-r /home/zaizeku/Desktop/test.txt";

Moreover, if you want to execute a complex command, I think "sh" (i.e.
/usr/bin/sh) would be better than "gnome-terminal",
and  the code would be:

Process pipes = new Process();
string command = "rm -r /home/zaizeku/Desktop/test.txt";
string tmpScript = "/tmp/cmd.txt";
File.WriteAllText(tmpScript , command);
pipes.StartInfo.FileName = "sh";
pipes.StartInfo.Arguments = tmpScript ;

BTW,  ur question is not related to gtk-sharp, I think the mono
mail-list is a better place to ask such question.


On Sun, Jun 7, 2009 at 2:06 AM, Zaizeku<zaizeku at gmail.com> wrote:
> Hey Guys I'm fairly new using C# on linux and well I'm having some trouble
> trying to execute a shell command from the code, I tried doing it the way I
> did it in C and C++ but to no avail, found some tutorials and guides on how
> to execute shell commands on C# but what I can only do is execute a program,
> what I really want to do is be able to execute a command like for example:
> rm -r <Directory>
> and well I'm not having any luck, here is what I have right now
>                System.Diagnostics.Process pipes = new System.Diagnostics.Process();
>                pipes.EnableRaisingEvents = false;
>                pipes.StartInfo.FileName = "gnome-terminal";
>                //pipes.StartInfo.Arguments = "rm -r /home/zaizeku/Desktop/test.txt";
>                pipes.Start();
> this does execute the terminal but the argument which I think would be the
> command is never even written/executed at all, I first tried just plainly
> doing this
>              System.Diagnostics.Process pipes = new
> System.Diagnostics.Process();
>              pipes.EnableRaisingEvents = false;
>              pipes.StartInfo.FileName = "rm -r
> /home/zaizeku/Desktop/test.txt";
>              pipes.Start();
> but it did not do anything, I'm really having a hard time finding a solution
> to this, so I ask you guys, can you help me figure this out, or tell me if
> its not possible.
> Thanks in Advance
> --
> View this message in context: http://www.nabble.com/Executing-Shell-commands-tp23904222p23904222.html
> Sent from the Mono - Gtk# mailing list archive at Nabble.com.
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

More information about the Gtk-sharp-list mailing list