命名管道名称可以有反斜杠吗?

发布于 2024-09-15 21:19:56 字数 1040 浏览 3 评论 0原文

根据 MSDN

[管道名称] 必须具有 以下表格:

\\.\pipe\pipename

名称的管道名部分可以 包括除 a 之外的任何字符 反斜杠,包括数字和 特殊字符。整个管道 名称字符串最多可达 256 个 字符长。管道名称不是 区分大小写。

但在很多例子中,我都看到命名管道名称中带有反斜杠。例如,SQL Server 的标准管道名称是 \\.\pipe\sql\query

从 SysInternals 运行 PipeList 会显示我的计算机上有大量管道,其中名称包含反斜杠。

那么,管道名称中可以包含反斜杠吗?

我问这个问题是因为我正在创建一个包含多个管道的服务,其名称如下:

\\.\pipe\MyApp
\\.\pipe\MyApp\0
\\.\pipe\MyApp\1
\\.\pipe\MyApp\2

创建第一个管道后,创建其他管道将失败,并出现 Windows 错误 123 (ERROR_INVALID_NAME)。如果我跳过创建第一个管道,则名称中带有反斜杠字符的所有其他管道都可以正常工作。

看起来管道像文件系统一样是分层的,如果您有一个具有特定名称的管道,则该名称不能再用作其他管道的“文件夹”或容器。

当试图弄清楚这一点时,我遇到了 MSDN< /a> 文章,现在我质疑我是否应该使用反斜杠。

有什么建议吗?

According to MSDN,

[The pipe name] must have the
following form:

\\.\pipe\pipename

The pipename part of the name can
include any character other than a
backslash, including numbers and
special characters. The entire pipe
name string can be up to 256
characters long. Pipe names are not
case sensitive.

But there are plenty of examples where I've seen named pipe names with backslashes in them. For example, the standard pipe name for SQL Server is \\.\pipe\sql\query.

Running PipeList from SysInternals reveals plenty of pipes on my machine where the name includes a backslash.

So, can a pipe name have a backslash in it or not?

I ask because I was creating a service with several pipes with names like this:

\\.\pipe\MyApp
\\.\pipe\MyApp\0
\\.\pipe\MyApp\1
\\.\pipe\MyApp\2

After the first pipe was created, creating the other pipes would fail with Windows error 123 (ERROR_INVALID_NAME). If I skipped creating the first pipe, all the others, with the backslash character in the name, would work just fine.

It appears that pipes are hierarchical like the file system, and if you have a pipe with a particular name, that name can no longer be used as a "folder" or container for other pipes.

When trying to figure this out, I came across the MSDN article and am now questioning whether I should be using backslashes at all.

Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˉ厌 2024-09-22 21:19:56

虽然这似乎是未记录的行为,但至少是一致的。只是不要创建与“文件夹”同名的管道。 Windows 在内部将命名管道实现为文件系统。但还要记住,恶意应用程序可能会创建 \.\pipe\MyApp 管道并导致您的应用程序失败。考虑到使用反斜杠的唯一好处是纯粹的语义,我建议使用下划线或其他字符。

While this appears to be undocumented behavior, it is at least consistent. Just don't create a pipe with the same name as a 'folder'. Windows implements named pipes as a filesystem internally. However also keep in mind that a malicious application could create a \.\pipe\MyApp pipe and cause your app to fail. Considering the only benefits of using the backslash are purely semantic, I would recommend using an underscore or other character instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文