为什么ReadLineAsync在Windows和Linux之间返回不同的结果

为什么ReadLineAsync在Windows和Linux之间返回不同的结果,linux,windows,.net-core,Linux,Windows,.net Core,考虑以下代码。 在Windows上,我在完成任务的结果中得到一个额外的\0,但在Linux上我没有。有人能解释一下原因吗 StreamReader _processOutput; #if (WINDOWS) var pipe = new NamedPipeClientStream(".", pipeFile, PipeDirection.In); await pipe.ConnectAsync(); #else var pipe = File.OpenRead(pipe

考虑以下代码。 在Windows上,我在完成任务的结果中得到一个额外的
\0
,但在Linux上我没有。有人能解释一下原因吗

StreamReader _processOutput;

#if (WINDOWS)
    var pipe = new NamedPipeClientStream(".", pipeFile, PipeDirection.In);
    await pipe.ConnectAsync();
#else
    var pipe = File.OpenRead(pipeFile);
#endif

_processOutput = new StreamReader(pipe);

var task = _processOutput.ReadLineAsync();

#if (WINDOWS)
     var result = task.Result.Replace("\0", "");  // <<<<< why do I get \0 ?
#else
     var result = task.Result;
#endif
StreamReader\u processOutput;
#如果(WINDOWS)
var pipe=new NamedPipeClientStream(“.”,pipeFile,PipeDirection.In);
等待pipe.ConnectAsync();
#否则
var pipe=File.OpenRead(pipeFile);
#恩迪夫
_processOutput=新的StreamReader(管道);
var task=_processOutput.ReadLineAsync();
#如果(WINDOWS)

var result=task.result.Replace(“\0”和“);//你的文件看起来像什么?特别是行尾字符。它不完全是一个文件,在两种情况下(Linux和Windows)都是一个命名管道,但在Linux中命名管道是一个特殊的文件,在Windows中,它是以相同方式运行的不同文件。管道是由另一个进程推动的“内容”。我的问题是为什么在Windows上有这个额外的
\0
字符。这与编码有关吗?是否与不同的行尾字符有关?@JanneHarju这也是我的想法,但我不确定。这可能是ReadLineSync中的错误。我假设他们没有使用这个。但也许您可以以某种方式使用它,即不使用ReadLineSync,而使用其他一些函数与此环境换行符。就像这里一样,但是您使用的不是/r而是Environment.Newline