lampac/Shared/Engine/Bash.cs
lampac-talks f843f04fd4 chore: initial commit 154.3
Signed-off-by: lampac-talks <lampac-talks@users.noreply.github.com>
2026-01-30 16:23:09 +03:00

58 lines
1.7 KiB
C#

using System.Diagnostics;
namespace Shared.Engine
{
public static class Bash
{
public static bool Invoke(string comand)
{
try
{
var processInfo = new ProcessStartInfo();
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.FileName = "/bin/bash";
processInfo.Arguments = $" -c \"{comand.Replace("\"", "\\\"").Replace("'", "\\\'")}\"";
var process = Process.Start(processInfo);
if (process == null)
return false;
return true;
}
catch
{
return false;
}
}
async public static Task<string> Run(string comand)
{
try
{
var processInfo = new ProcessStartInfo();
processInfo.UseShellExecute = false;
processInfo.RedirectStandardError = true;
processInfo.RedirectStandardOutput = true;
processInfo.FileName = "/bin/bash";
processInfo.Arguments = $" -c \"{comand.Replace("\"", "\\\"").Replace("'", "\\\'")}\"";
var process = Process.Start(processInfo);
if (process == null)
return null;
string outPut = await process.StandardOutput.ReadToEndAsync();
outPut += await process.StandardError.ReadToEndAsync();
await process.WaitForExitAsync();
return outPut;
}
catch
{
return null;
}
}
}
}