NamedPipeServerStream无法在Windows 10上运行(适用于Windows 7)

Mul*_*deR 7 c# ipc pipe windows-10

看来,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.");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,如果我运行此程序,管道将成功创建.但是,在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.
Run Code Online (Sandbox Code Playgroud)

在那之后,"主要"程序说管道坏了.

令人困惑的是,完全相同的程序在Windows 7上正常工作:文本"Hallo world!" 可以从终端中的管道读取(使用与上面完全相同的命令)就好了:

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

C:\Users\testuser>type \\.\pipe\testpipe
Hallo!
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

谢谢!


背景:

我的目标是将字符串(密码)传递给命令行应用程序,该应用程序无法直接从命令行获取字符串.相反,命令行程序只能获取文件名,并将从指定的文件中读取字符串.但是我不想创建一个(临时的)"物理"文件,而是想通过命名管道传递字符串 - 就像我在Unix上用mkfifo做的那样.

(我无法更改命令行程序)

Zir*_*iax -1

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

MSDN 文档现在声明如下:

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

非常不清楚这意味着什么......