【发布时间】:2013-12-22 05:38:54
【问题描述】:
我在 Windows Powershell 中创建了以下命名管道。
# .NET 3.5 is required to use the System.IO.Pipes namespace
[reflection.Assembly]::LoadWithPartialName("system.core") | Out-Null
$pipeName = "pipename"
$pipeDir = [System.IO.Pipes.PipeDirection]::InOut
$pipe = New-Object system.IO.Pipes.NamedPipeServerStream( $pipeName, $pipeDir )
现在,我需要一些 Python 代码 sn-p 从上面创建的命名管道中读取。 Python可以做到吗?
提前致谢!
【问题讨论】:
-
你试过 Python 中的
data = open(r'\\.\pipe\pipename', 'rb', 0).read()吗? -
感谢 J.F,但我的 powershell namedpipe 等待连接,当我开始 .read() 操作时,namedpipe 不知何故被关闭。是否还有其他东西而不是 read(),例如 connect() 或其他东西,以便我最初建立连接,然后执行读写操作。如果我错了,请纠正我
-
谢谢 J.F 我现在可以使用了。非常感谢。我将复制下面运行良好的那个
标签: python windows powershell named-pipes