Follow

接个管道

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]);
· · Web · 0 · 0 · 0
Sign in to participate in the conversation
小森林

每个人都有属于自己的一片森林,也许我们从来不曾走过,但它一直在那里,总会在那里。迷失的人迷失了,相逢的人会再相逢。愿这里,成为属于你的小森林。