错误的文件描述符管道Win32 API

时间:2012-12-12 14:03:42

标签: c++ winapi pipe

以下代码总是会给我一个错误,例如read file child: Bad file descriptorread file child: No error

父创建子进程,从匿名父管道读取数据。从std。

获取HANDLE时出错

parent.cpp:

sinfo.hStdInput = pipe_read;
/****some code********/
if(!CreateProcess(0, szCmdline, 0, 0, 0, 0, 0, 0, &sinfo, &pinfo))
{
    perror("create process");
    exit(1);
}
/****some code********/

if(!WriteFile(pipe_write, &to_process, sizeof(int)*20, &bytes, 0))
{
    perror("write file parent");
    exit(1);
}

vector<int> sorted;
if(!ReadFile(pipe_read1, &sorted, sizeof(int)*20, 0, 0))
{
    perror("read file parent");
    exit(1);
}

child.cpp:

/****some code********/

HANDLE pipe_read = GetStdHandle(STD_INPUT_HANDLE);

/****some code********/

if(!ReadFile(pipe_read, &to_process, sizeof(int)*20, &bytes, 0))
{
    perror("read file child");
    exit(1);
}
/****some code********/

我的代码有什么问题?收到的(在孩子中)和转发的(在父母中)的地址是等于。

0 个答案:

没有答案