|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Executing Shell commandsHey 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 |
|
|
Re: Executing Shell commandsHey, 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 ; pipes.Start(); ... BTW, ur question is not related to gtk-sharp, I think the mono mail-list is a better place to ask such question. B.R. Matt On Sun, Jun 7, 2009 at 2:06 AM, Zaizeku<zaizeku@...> 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@... > http://lists.ximian.com/mailman/listinfo/gtk-sharp-list > Gtk-sharp-list maillist - Gtk-sharp-list@... http://lists.ximian.com/mailman/listinfo/gtk-sharp-list |
|
|
Re: Executing Shell commandsThank you so much you solved my problem, and sorry I thought the question was relevant here, well anyway thanks for taking your time to actually answer my question I really appreciate it =) |
| Free embeddable forum powered by Nabble | Forum Help |