在Windows中读/写linux命名管道(fifo)

时间:2016-01-12 20:46:00

标签: c# linux windows fifo smb

我想在使用C#的Windows应用程序的SMB共享中读取和编写在Linux中创建的fifo。似乎如果我尝试从管道读取就好像它是直接使用StreamReader的普通文件一样,它到达流的末尾而不实际检索任何数据。如果我尝试使用NamedPipeClientStream,则会引发IOException陈述A volume has been accessed for which a file system driver is required that has not yet been loaded.这让我觉得这可能不可行。 Windows中的命名管道与Linux完全不同吗?如果是这样,我可以将其视为普通文件吗?

这是我先使用的代码:

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

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

非常简单;在Linux系统中,我有一个文本文件,其中有几行无意义,我cat到管道。这会阻塞,正如我所期望的那样,然后我运行列出的代码,打印出“已完成”,就像它到达流的末尾一样。这也解除了Linux端cat的阻塞,我觉得这很不稳定。

以下是我与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);
    }
}

这就是抛出异常 - 我假设Windows命名管道不是我在这里寻找的东西,我将不得不阅读更多关于它们的内容。非常感谢任何帮助。

0 个答案:

没有答案
相关问题