46 args.m_output_bytes.clear();
53 int r0 = pipe2(pipefd_out,O_CLOEXEC);
56 r0 = pipe2(pipefd_in,O_CLOEXEC);
59 pid_t cpid = ::fork();
70 ::close(STDOUT_FILENO);
71 ::close(pipefd_out[0]);
72 ::dup2(pipefd_out[1],STDOUT_FILENO);
75 ::close(STDIN_FILENO);
76 ::close(pipefd_in[1]);
77 ::dup2(pipefd_in[0],STDIN_FILENO);
85 UniqueArray<const char*> command_args(nb_arg+2);
86 for(
Integer i=0; i<nb_arg; ++i )
87 command_args[i+1] = arguments[i].localstr();
88 command_args[0] = cmd_name;
89 command_args[nb_arg+1] =
nullptr;
91 const char *
const newenviron[] = { NULL };
92 ::execve(cmd_name, (
char*
const*)command_args.data(), (
char*
const*)newenviron);
97 ::close(pipefd_out[1]);
98 ::close(pipefd_in[0]);
100 Int64 nb_wanted_write = input_bytes.
size();
101 Int64 nb_written = ::write(pipefd_in[1],input_bytes.
data(),nb_wanted_write);
102 if (nb_written!=nb_wanted_write)
103 std::cerr <<
"Error writing to pipe\n";
104 ::close(pipefd_in[1]);
105 const int BUF_SIZE=4096;
109 while ((r=::read(pipefd_out[0], buf, BUF_SIZE)) > 0){
118 child_pid = ::waitpid(cpid,&status,0);
119 }
while (child_pid == -1 && errno == EINTR);
121 if (WIFEXITED(status)){
122 args.m_exit_code = WEXITSTATUS(status);
126 exec_status = ProcessExecArgs::ExecStatus::AbnormalExit;
128 close(pipefd_out[0]);
131 args.m_output_bytes.add(
'\0');