3

Consider the following code. On Windows I get an extra \0 in the result of the completed task, but on Linux I don't. Can someone explain why?

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
Tomm
  • 1,021
  • 2
  • 14
  • 34
ipinak
  • 5,739
  • 3
  • 23
  • 41
  • What does your file look like? Specifically the line ending characters. – SpruceMoose Dec 22 '17 at 09:50
  • It's not exactly a file, it's a named pipe in both case (Linux & Windows), but in Linux a named pipe is a special file, in windows it's something different which acts the same way. The pipe is "contents" are pushed by another process. My question is why there is this extra `\0` character on Windows. Is it related to encoding? – ipinak Dec 22 '17 at 10:39
  • Can it be something to do with different line-ending character? – Janne Harju Dec 22 '17 at 18:16
  • @JanneHarju that is what I was thinking as well, but I'm not sure. – ipinak Dec 25 '17 at 07:22
  • It might be bug in ReadLineAsync. I assume that they are not using this [Environment.NewLine](https://msdn.microsoft.com/en-us/library/system.environment.newline(v=vs.110).aspx). But maybe you can use this in someway i.e. not using ReadLineAsync instead using some other function with this environment newline. Like here https://stackoverflow.com/a/6655285/8081009 but instead of /r you use Environment.Newline – Janne Harju Dec 25 '17 at 08:22

0 Answers0