using System.Diagnostics; namespace iWare.Wms.Core { /// /// 系统Shell命令 /// public class ShellUtil { /// /// Bash命令 /// /// /// public static string Bash(string command) { var escapedArgs = command.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(); process.Dispose(); return result; } /// /// cmd命令 /// /// /// /// public static string Cmd(string fileName, string args) { string output = string.Empty; var info = new ProcessStartInfo { FileName = fileName, Arguments = args, RedirectStandardOutput = true }; using (var process = Process.Start(info)) { output = process.StandardOutput.ReadToEnd(); } return output; } } }