【问题标题】:NamedPipeServerStream not working on Windows 10 (works in Windows 7)NamedPipeServerStream 在 Windows 10 上不工作(在 Windows 7 上工作)
【发布时间】:2019-02-09 21:23:32
【问题描述】:

NamedPipeServerStream 似乎在 Windows 10 上运行。

我正在使用以下代码从我的 C# 应用程序创建命名管道。此代码已直接从 MSDN 示例中复制,所以应该是正确的,我想:

class Program
{
    static void Main(string[] args)
    {
        using (NamedPipeServerStream pipeServer =
                new NamedPipeServerStream("testpipe", PipeDirection.Out))
        {
            Console.WriteLine("NamedPipeServerStream object created.");
            Console.Write("Waiting for client connection... ");
            pipeServer.WaitForConnection();
            Console.WriteLine("Client connected.");
            try
            {
                using (StreamWriter sw = new StreamWriter(pipeServer))
                {
                    sw.AutoFlush = true;
                    sw.WriteLine("Hallo world!");
                    Console.WriteLine("Data was written.");
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
            }
            Console.WriteLine("Pipe closed.");
        }
    }
}

现在,如果我运行这个程序,管道就创建成功了。但是,在 Windows 10 上,每次从终端中的管道读取的尝试都会失败立即并出现错误 “所有管道实例都忙"

Microsoft Windows [Version 10.0.17134.228]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\MuldeR>type \\.\pipe\testpipe
All pipe instances are busy.

紧接着,“主”程序说管道坏了。

令人困惑的是,完全相同的程序可以在 Windows 7 上正常运行:文本“你好世界!”可以从终端的管道中读取(使用与上面完全相同的命令)就好了:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Alle Rechte vorbehalten.

C:\Users\testuser>type \\.\pipe\testpipe
Hallo!

我错过了什么???

谢谢!


背景:

我的目标是将字符串(密码)传递给命令行应用程序,该应用程序无法直接从命令行获取字符串。相反,命令行程序只能采用文件名,并从指定文件中读取字符串。但我不想创建一个(临时)“物理”文件,而是想通过命名管道传递字符串 - 以类似的方式,我会在 Unix 上使用 mkfifo

(我可以更改命令行程序)

【问题讨论】:

  • 您找到解决方案了吗?我有类似的问题

标签: c# windows-10 pipe ipc


【解决方案1】:

我们的软件与许多客户端都存在类似问题,似乎某些版本的 Windows 10 破坏了命名管道,非常令人沮丧。

MSDN 文档现在声明如下:

Windows 10 版本 1709:管道仅在应用容器中受支持;即,从一个 UWP 进程到属于同一应用程序的另一个 UWP 进程。此外,命名管道必须使用语法“\.\pipe\LOCAL\”作为管道名称。

不清楚这是什么意思……

【讨论】:

猜你喜欢
  • 2011-09-11
  • 2012-07-04
  • 2020-03-11
  • 2022-07-05
  • 1970-01-01
  • 1970-01-01
  • 2017-08-05
  • 2016-07-09
  • 1970-01-01
相关资源
最近更新 更多