![](/img/trans.png)
[英]WriteFile and ReadFile on child process's stdio (using overlapped named pipe)
[英]Writing to openssl's stdio in C using pipe
我试图将一些数据传递给openssl,如下所示:
int fd[2];
char buff[MAXBUFF];
pid_t childpid;
pipe(fd);
childpid = fork();
if (childpid == 0){
dup2(0, fd[0]);
close(fd[1]);
execlp("openssl", "s_client", "-connect", "imap.gmail.com:993", "-crlf", NULL);
}
else {
close(fd[0]);
dosomething(buff);
write(fd[1], buff, strlen(buff) + 1);
sleep(4);
}
但似乎openssl没有从buff获取数据,它只是等待我认为的一些输入。 如果我用bash做同样的事情
灰:
.
.
.
echo $data
sleep 3
.
.
.
b.sh:
openssl s_client -connect imap.gmail.com:993 -crlf
./a.sh | ./b.sh
一切正常。
你切换了dup2()
的参数。
原型是:
int dup2(int oldfd, int newfd);
所以你应该这样做
dup2(fd[0], 0);
将fd[0]
设置为子进程的stdin。 然后它应该按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.