Skip to content

允许对执行命令进行过滤,解决执行命令输出乱码 #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions DotNETBuild/Utils/DotNetBuildTools_/DotNetBuildTool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Diagnostics;

using dotnetCampus.Configurations;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -41,9 +44,10 @@ protected DotNetBuildTool(IAppConfigurator appConfigurator, ILogger logger = nul
/// <param name="arguments"></param>
/// <param name="workingDirectory">默认将使用当前进程工作路径</param>
/// <param name="needAutoLogOutput">是否实时输出</param>
/// <param name="processStartInfoFilter">用于对输入过程的过滤。如设置编码等</param>
/// <returns></returns>
protected ProcessResult ExecuteProcessCommand(string exeName, string arguments,
string workingDirectory = "", bool needAutoLogOutput = true)
string workingDirectory = "", bool needAutoLogOutput = true, Action<ProcessStartInfo>? processStartInfoFilter = null)
{
Logger.LogInformation($"{exeName} {arguments}");

Expand All @@ -61,7 +65,7 @@ protected ProcessResult ExecuteProcessCommand(string exeName, string arguments,
Logger.LogWarning(message);
}
}
});
}, processStartInfoFilter);
Logger.LogInformation($"ExitCode: {result.ExitCode}");

return result;
Expand Down
6 changes: 5 additions & 1 deletion DotNETBuild/Utils/ProcessRunner_/ProcessRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ public static class ProcessRunner
/// <param name="arguments"></param>
/// <param name="workingDirectory"></param>
/// <param name="onReceivedOutput">当收到进程输出触发</param>
/// <param name="processStartInfoFilter">用于对输入过程的过滤。如设置编码等</param>
/// <returns></returns>
public static ProcessResult ExecuteCommand(string exeName, string arguments,
string workingDirectory = "", Action<ProcessOutputInfo>? onReceivedOutput = null)
string workingDirectory = "", Action<ProcessOutputInfo>? onReceivedOutput = null, Action<ProcessStartInfo>? processStartInfoFilter = null)
{
var processStartInfo = new ProcessStartInfo
{
Expand All @@ -38,6 +39,8 @@ public static ProcessResult ExecuteCommand(string exeName, string arguments,
//StandardOutputEncoding = Encoding.UTF8
};

processStartInfoFilter?.Invoke(processStartInfo);

var processOutputInfoList = new List<ProcessOutputInfo>();

var process = new Process();
Expand Down Expand Up @@ -80,5 +83,6 @@ public static ProcessResult ExecuteCommand(string exeName, string arguments,
processOutputInfoList.TrimExcess();
return new ProcessResult(exitCode, processOutputInfoList);
}

}
}
Loading