gpt4 book ai didi

c# - C# 中的系统命令

转载 作者:太空宇宙 更新时间:2023-11-04 06:04:50 25 4
gpt4 key购买 nike

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

我该如何在 C# 中执行此操作?

    system("ls -al");

我在 Linux 上使用 Mono。

最佳答案

没问题,我明白了。

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# - C# 中的系统命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25281641/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com