【发布时间】:2014-10-06 13:06:17
【问题描述】:
C# 是否与 C 中的系统命令等效?例如,
我将如何在 c# 中做到这一点?
system("ls -al");
我在 Linux 上使用 Mono。
【问题讨论】:
-
如此多的反对票,但 python 中的类似问题却获得了超过 1000 票。 stackoverflow.com/questions/89228/…
C# 是否与 C 中的系统命令等效?例如,
我将如何在 c# 中做到这一点?
system("ls -al");
我在 Linux 上使用 Mono。
【问题讨论】:
您可以使用 Process.Start() 方法。 看ProcessStartinfo.UseShellExecute
【讨论】:
没问题,我明白了。
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"