Files
Hua.DotNet.Code/Helper/ShellHelper.cs

37 lines
826 B
C#

using System.Diagnostics;
namespace Hua.DotNet.Code.Helper;
public static class ShellHelper
{
public static string Bash(string command)
{
string text = command.Replace("\"", "\\\"");
Process process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = "-c \"" + text + "\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
};
process.Start();
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
process.Dispose();
return result;
}
public static string Cmd(string fileName, string args)
{
using Process process = Process.Start(new ProcessStartInfo
{
FileName = fileName,
Arguments = args,
RedirectStandardOutput = true
});
return process.StandardOutput.ReadToEnd();
}
}