You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
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;
|
|
}
|
|
}
|
|
} |