PowerShell version removed — will use OV code signing certificate instead. Files moved back from src/ to project root. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
64 sor
2.0 KiB
C#
64 sor
2.0 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace InstaSoftOfficeTool.Services
|
|
{
|
|
public class ProcessRunner
|
|
{
|
|
public event Action<string> OutputReceived;
|
|
|
|
public async Task<int> RunAsync(string fileName, string arguments, bool redirectOutput = true)
|
|
{
|
|
var psi = new ProcessStartInfo
|
|
{
|
|
FileName = fileName,
|
|
Arguments = arguments,
|
|
UseShellExecute = false,
|
|
CreateNoWindow = true,
|
|
RedirectStandardOutput = redirectOutput,
|
|
RedirectStandardError = redirectOutput,
|
|
StandardOutputEncoding = redirectOutput ? Encoding.UTF8 : null,
|
|
StandardErrorEncoding = redirectOutput ? Encoding.UTF8 : null
|
|
};
|
|
|
|
using (var process = new Process { StartInfo = psi })
|
|
{
|
|
if (redirectOutput)
|
|
{
|
|
process.OutputDataReceived += (s, e) =>
|
|
{
|
|
if (e.Data != null)
|
|
OutputReceived?.Invoke(e.Data);
|
|
};
|
|
process.ErrorDataReceived += (s, e) =>
|
|
{
|
|
if (e.Data != null)
|
|
OutputReceived?.Invoke("[HIBA] " + e.Data);
|
|
};
|
|
}
|
|
|
|
process.Start();
|
|
|
|
if (redirectOutput)
|
|
{
|
|
process.BeginOutputReadLine();
|
|
process.BeginErrorReadLine();
|
|
}
|
|
|
|
await Task.Run(() => process.WaitForExit());
|
|
return process.ExitCode;
|
|
}
|
|
}
|
|
|
|
public async Task<string> RunAndCaptureAsync(string fileName, string arguments)
|
|
{
|
|
var sb = new StringBuilder();
|
|
OutputReceived += line => sb.AppendLine(line);
|
|
await RunAsync(fileName, arguments);
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|