v1.16 — Remove PowerShell edition, restore flat project structure
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>
This commit is contained in:
63
Services/ProcessRunner.cs
Normal file
63
Services/ProcessRunner.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user