int pstdin [2];
int pstdout[2];
pipe(pstdin);
pipe(pstdout);
switch (child = vfork())
{
case -1: // error
perror("fork failed");
exit(EXIT_FAILURE);
break;
case 0: // child
dup2(pstdin [0], 0);
dup2(pstdout[1], 1);
close(pstdin [1]);
close(pstdout[0]);
execlp("pinentry", "pinentry");
perror("execlp just return");
exit(EXIT_FAILURE);
break;
default: // parent
close(pstdin [0]);
close(pstdout[1]);
break;
}
write(pstdin[1], "input\n", 6);
read(pstdout[0], buff, len);
waitpid(child, NULL, 0);
close(pstdin [1]);
close(pstdout[0]);
莉特雅 literal
写代码业余爱好者 amateur coder