Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
weibaohui committed May 28, 2024
1 parent e84da4e commit ed40984
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions BlazorApp/Utils/ProcessManager.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Extensions.Logging;
Expand All @@ -9,8 +10,9 @@ public class ProcessManager
private static readonly ILogger<ProcessManager> Logger = LoggingHelper<ProcessManager>.Logger();
private readonly Dictionary<string, Process> _services = new Dictionary<string, Process>();


public static ProcessManager Instance => Nested.Instance;
public event EventHandler<string> StandardOutput;
public event EventHandler<string> StandardError;

public void StartService(string name, string binPath, string args)
{
Expand All @@ -35,8 +37,16 @@ public void StartService(string name, string binPath, string args)
}
};

process.OutputDataReceived += (sender, arg) => Logger.LogInformation("[{Name}] 输出: {ArgData}", name, arg.Data);
process.ErrorDataReceived += (sender, arg) => Logger.LogInformation("[{Name}] 错误: {ArgData}", name, arg.Data);
process.OutputDataReceived += (sender, arg) =>
{
StandardOutput?.Invoke(sender, arg.Data);
Logger.LogInformation("[{Name}] 输出: {ArgData}", name, arg.Data);
};
process.ErrorDataReceived += (sender, arg) =>
{
StandardError?.Invoke(sender, arg.Data);
Logger.LogInformation("[{Name}] 错误: {ArgData}", name, arg.Data);
};

process.Start();
process.BeginOutputReadLine();
Expand Down

0 comments on commit ed40984

Please sign in to comment.