1

I would like to read and write a fifo created in Linux on an SMB share from an application in Windows using C#. It seems that if I try to read from the pipe as if it were a normal file using StreamReader directly, it reaches the end of the stream without actually retrieving any data. If I try using NamedPipeClientStream, it throws an IOException stating A volume has been accessed for which a file system driver is required that has not yet been loaded. This makes me think maybe this isn't doable. Are Named Pipes in Windows completely different from Linux? If so, can I treat this as a normal file?

Here is the code I used first:

StreamReader file = new StreamReader(@"\\mvssuperos7\shared\lread");
String line;
while ((line = file.ReadLine()) != null)
{
    Console.WriteLine(line);
}

file.Close();
Console.WriteLine("Finished");
Console.ReadLine();

Pretty straightforward; from the Linux system, I have a text file with several lines of nonsense which I cat to the pipe. This blocks, as I would expect it to, then I run the listed code, which prints "Finished" as if it reached the end of the stream. This also unblocks cat on the Linux end, which I find precarious.

Here is the code I used with NamedPipeClientStream:

StreamReader file = new StreamReader(@"\\mvssuperos7\shared\lread");
using (NamedPipeClientStream pipeClient =
new NamedPipeClientStream(@"mvssuperos7", "shared/lread", PipeDirection.In))
{

// to the pipe or wait until the pipe is available.
Console.Write("Attempting to connect to pipe...");
pipeClient.Connect();

Console.WriteLine("Connected to pipe.");
Console.WriteLine("There are currently {0} pipe server instances open.",
pipeClient.NumberOfServerInstances);
using (StreamReader sr = new StreamReader(pipeClient))
{
    // Display the read text to the console
    string temp;
    while ((temp = sr.ReadLine()) != null)
    {
        Console.WriteLine("Received from server: {0}", temp);
    }
}

This is what is throwing the Exception -- I'm assuming Windows Named Pipes are not what I'm looking for here, I'll have to read more about them. Any help is greatly appreciated.

bkane521
  • 386
  • 2
  • 10
  • Linux pipes are not Windows pipes. See http://stackoverflow.com/questions/3960221/windows-named-pipe-support-in-Linux. Why did the streamreader not work? Or did it? – Niels V Jan 12 '16 at 21:24
  • The streamreader seems to immediately reach the end of the stream, regardless of what I send through the pipe. I'm not sure if I'm making a mistake in my code or if this type of thing just won't work. – bkane521 Jan 12 '16 at 21:27
  • What I read up to now, fifo Linux pipes only live in memory, so no content is written to disk. With your StreamReader you're reading the disk. – Niels V Jan 12 '16 at 21:36
  • Hmm I suppose this probably won't be possible then – bkane521 Jan 12 '16 at 22:04
  • Unless the SMB service (Samba?) explicitly supports doing this, it almost certainly won't work. – Harry Johnston Jan 13 '16 at 00:57

0 Answers0