using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace IoTDameon { public static class ShellHelper { public static string Bash(this string cmd) { var fileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "powershell" : "/bin/bash"; var escapedArgs = cmd.Replace("\"", "\\\""); var process = new Process() { StartInfo = new ProcessStartInfo { FileName = fileName, Arguments = $"-c \"{escapedArgs}\"", RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, } }; Console.WriteLine($"# {fileName} {escapedArgs}"); process.Start(); string result = process.StandardOutput.ReadToEnd(); process.WaitForExit(); process.Refresh(); process.Close(); return result; } } }