-4

Does C# have an equivalent to the system command in C? for example,

how would I do this in c#?.

    system("ls -al");

I'm using Mono on Linux.

Dave Carruthers
  • 502
  • 1
  • 7
  • 25
  • So many down votes yet a similar question in python gets over 1000 up votes. http://stackoverflow.com/questions/89228/calling-an-external-command-in-python?rq=1 – Dave Carruthers Aug 14 '14 at 17:36

2 Answers2

0

You can use Process.Start() method. Look at ProcessStartinfo.UseShellExecute

Evgeny Gorbovoy
  • 674
  • 3
  • 19
0

No problem I got it.

public static void system(string command)
    {
        //No arguments
        if(command.IndexOf(' ')== -1)
        {
            Process.Start(command);
        }
        else 
        {
            string cmd = command.Substring(0, command.IndexOf(' '));
            string args = command.Substring(command.IndexOf(' ')+1);
            Process.Start(cmd, args);
        }
    }

Tested and working on Ubuntu 13.10

Dave Carruthers
  • 502
  • 1
  • 7
  • 25