为什么在读取 Ubuntu 命令输出时会出现管道损坏错误?

时间:2021-05-27 07:31:27

标签: .net linux

代码如下:

var commandStartInfo = new ProcessStartInfo("id") { RedirectStandardOutput = true };
var command = Process.Start(commandStartInfo);
command.Start();
while (!command.StandardOutput.EndOfStream) {
    var line = await command.StandardOutput.ReadLineAsync();
    Logger.LogInformation("id: " + line);
}
await command.WaitForExitAsync(cancellationToken);

这是一个系统服务。我只是测试一下。

输出如下:

May 27 06:58:21 my-vm dotnet[2257]: id: write error: Broken pipe
May 27 06:58:21 my-vm dotnet[2231]: test.Service.SystemService[0] id: uid=0(root) gid=0(root) groups=0(root)

为什么会出现这个错误?我应该如何开始我的流程才不会出现该错误?

0 个答案:

没有答案