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