【问题标题】:System commands in c#c#中的系统命令
【发布时间】:2014-10-06 13:06:17
【问题描述】:

C# 是否与 C 中的系统命令等效?例如,

我将如何在 c# 中做到这一点?

    system("ls -al");

我在 Linux 上使用 Mono。

【问题讨论】:

标签: c# linux command system


【解决方案1】:

您可以使用 Process.Start() 方法。 看ProcessStartinfo.UseShellExecute

【讨论】:

    【解决方案2】:

    没问题,我明白了。

    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);
            }
        }
    

    在 Ubuntu 13.10 上测试并运行

    【讨论】:

    • 不适用于"C:\Program Files (x86)\Internet Explorer\iexplore.exe"
    • 好点,应该提到这是针对 Linux 的。在 Ubuntu 13.10 上测试
    猜你喜欢
    • 1970-01-01
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    • 2012-09-13
    • 1970-01-01
    • 2021-07-07
    • 2016-03-11
    • 1970-01-01
    相关资源
    最近更新 更多