CommandHelperExecuteWithOutputAsync 方法

执行命令并获取输出(异步)。

Definition

命名空间: Suresking.Utility
程序集: Suresking.Utility (在 Suresking.Utility.dll 中) 版本:1.3.22+a27276bb8ffde055e69ff608e98aafba279e1e99
C#
public static Task<CommandResult> ExecuteWithOutputAsync(
	string command,
	string? workingDirectory = null,
	CancellationToken cancellationToken = default
)

参数

command  String
要执行的命令。
workingDirectory  String  (Optional)
工作目录。如果为 null,使用当前进程的工作目录。
cancellationToken  CancellationToken  (Optional)
取消令牌。

返回值

TaskCommandResult
包含退出码、标准输出和标准错误的 CommandResult 对象。

备注

关于 dotnet format 的退出码:

  • 0:成功,代码符合格式规范
  • 1:错误,执行过程发生异常
  • 2:使用 --verify-no-changes 时发现需要格式化的代码

取消行为:

当取消令牌触发时,会终止整个进程树(包括可能产生的子进程)。

参见