mirror of
https://github.com/ryzij/ServerMonitor.git
synced 2026-07-14 03:46:58 +00:00
27 lines
781 B
C#
27 lines
781 B
C#
using MonitorAgent.Core.Abstraction;
|
|
using System.Diagnostics;
|
|
|
|
namespace MonitorAgent.Application.Services;
|
|
|
|
public class ProcessStarterService : IProcessStarterService
|
|
{
|
|
public async Task<string> StartProcessAsync(
|
|
string fileName, string arguments, CancellationToken cancellationToken = default)
|
|
{
|
|
using var process = new Process
|
|
{
|
|
StartInfo = new ProcessStartInfo
|
|
{
|
|
FileName = fileName,
|
|
Arguments = arguments,
|
|
UseShellExecute = false,
|
|
RedirectStandardOutput = true,
|
|
RedirectStandardError = true
|
|
}
|
|
};
|
|
|
|
process.Start();
|
|
|
|
return await process.StandardOutput.ReadToEndAsync(cancellationToken);
|
|
}
|
|
} |