David R.S. Robinson
public text v1 · immutablevoid 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); }}