--- execute_cmd.c +++ execute_cmd.c 2010-06-23 09:58:23.119134909 +0200 @@ -1525,7 +1525,7 @@ static struct cpelement *cpl_search __P( static struct cpelement *cpl_searchbyname __P((char *)); static void cpl_prune __P((void)); -Coproc sh_coproc = { 0, NO_PID, -1, -1, 0, 0 }; +Coproc sh_coproc = { 0, NO_PID, -1, -1, 0, 0, 0, 0 }; cplist_t coproc_list = {0, 0, 0}; @@ -2053,7 +2053,7 @@ execute_pipeline (command, asynchronous, int asynchronous, pipe_in, pipe_out; struct fd_bitmap *fds_to_close; { - int prev, fildes[2], new_bitmap_size, dummyfd, ignore_return, exec_result; + int lstdin, prev, fildes[2], new_bitmap_size, dummyfd, ignore_return, exec_result; COMMAND *cmd; struct fd_bitmap *fd_bitmap; @@ -2148,8 +2148,26 @@ execute_pipeline (command, asynchronous, /* Now execute the rightmost command in the pipeline. */ if (ignore_return && cmd) cmd->flags |= CMD_IGNORE_RETURN; + + lstdin = -1; + if (!asynchronous && pipe_out == NO_PIPE && prev > 0) + { + lstdin = move_to_high_fd(0, 0, 64); + if (lstdin > 0) + { + dup2(prev, 0); + prev = NO_PIPE; + } + } + exec_result = execute_command_internal (cmd, asynchronous, prev, pipe_out, fds_to_close); + if (lstdin > 0) + { + dup2(lstdin, 0); + close(lstdin); + } + if (prev >= 0) close (prev);