All pastes #270382 Raw Edit

David R.S. Robinson

public text v1 · immutable
·published 2006-12-07 09:13 UTC
rendered paste body
void spawn(char *command, int fd_stdin, int fd_stdout){  int pid;  pid = ufork();  if (pid)  {    /* Close any spare file descriptors. */    fd_stdin  != STDIN  ? close(fd_stdin)  : 0;    fd_stdout != STDOUT ? close(fd_stdout) : 0;  }  else  {    printf("spawn('%s', %u, %u) = %u\n", command, fd_stdin, fd_stdout, pid);    if (fd_stdin != STDIN)    {      close(STDIN);      dup2(fd_stdin, STDIN);    }    if (fd_stdout != STDOUT)    {      close(STDOUT);      dup2(fd_stdout, STDOUT);    }    exec(command);  }}