【发布时间】:2012-02-15 20:17:01
【问题描述】:
我正在 C++ 中创建一个管道,当我尝试使用 php 代码写入该管道时,当我尝试获取该管道的句柄时,它给了我访问被拒绝错误。 基本上,php代码调用另一个写入管道的c++ exe,但它失败了。我认为它死于用户没有的某些安全性或访问权限(php用户)。 有什么想法吗??
代码c++
hPipe = CreateNamedPipe(
wcPipeName, // pipe name
PIPE_ACCESS_DUPLEX, // read/write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances
1024, // output buffer size
1024, // input buffer size
NMPWAIT_USE_DEFAULT_WAIT, // client time-out
NULL);
从 php 调用的编写代码客户端
hPipe = CreateFile(
lpszPipename, // pipe name
GENERIC_READ, // read and write access
0, // no sharing
NULL, // default security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file
if (hPipe == INVALID_HANDLE_VALUE)
{
printf("\nCreatePipe failed\n %d \n",GetLastError());
return FALSE;
}
//Sleep(1000);
// Write the reply to the pipe.
fSuccess = WriteFile(
hPipe, // handle to pipe
Buffer, // buffer to write from
BufferSize-1, // number of bytes to write
&cbWritten, // number of bytes written
NULL); // not overlapped I/O
FlushFileBuffers(hPipe);
CloseHandle(hPipe);
【问题讨论】:
-
我有个想法:贴一些代码。 :)
-
你能发布客户端和服务器 c++ 代码吗?它在什么平台上运行?这两个进程是否以同一用户身份运行?
-
没有 php 代码以 iis 用户身份运行
-
发布了代码。错误是 createfile 中的访问被拒绝
标签: php c++ ipc named-pipes