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.
47 lines
1.3 KiB
47 lines
1.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
|
|
namespace Wood.Util
|
|
{
|
|
public class ShellHelper
|
|
{
|
|
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;
|
|
}
|
|
|
|
public static string? Cmd(string fileName, string args)
|
|
{
|
|
string? output = string.Empty;
|
|
|
|
var info = new ProcessStartInfo();
|
|
info.FileName = fileName;
|
|
info.Arguments = args;
|
|
info.RedirectStandardOutput = true;
|
|
|
|
using (var process = Process.Start(info))
|
|
{
|
|
output = process?.StandardOutput.ReadToEnd();
|
|
}
|
|
return output;
|
|
}
|
|
}
|
|
}
|
|
|