Skip to content
Advertisement

System commands in c#

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.

Advertisement

Answer

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

Advertisement