Роман Тимохов Asked:2020-09-10 20:21:08 +0000 UTC2020-09-10 20:21:08 +0000 UTC 2020-09-10 20:21:08 +0000 UTC .Net Core 调用命令 772 我在 Linux 机器上安装了通过命令工作的软件(例如 wert-qw --f )需要在 .Net Core 上以编程方式调用这些命令。如何正确实施? c# 1 个回答 Voted Best Answer KoVadim 2020-09-10T21:01:09Z2020-09-10T21:01:09Z 这是一个很好的例子 using System; using System.Diagnostics; public static class ShellHelper { public static string Bash(this string cmd) { var escapedArgs = cmd.Replace("\"", "\\\""); var process = new Process() { StartInfo = new ProcessStartInfo { FileName = "/bin/bash", Arguments = $"-c \"{escapedArgs}\"", RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, } }; process.Start(); string result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); return result; } } 和挑战 var output = "ps aux".Bash();
这是一个很好的例子
和挑战