46 args.m_output_bytes.
clear();
53 int r0 = pipe2(pipefd_out,O_CLOEXEC);
55 return ProcessExecArgs::ExecStatus::CanNotCreatePipe;
56 r0 = pipe2(pipefd_in,O_CLOEXEC);
58 return ProcessExecArgs::ExecStatus::CanNotCreatePipe;
59 pid_t cpid = ::fork();
61 return ProcessExecArgs::ExecStatus::CanNotFork;
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);
82 Integer nb_arg = arguments.
size();
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){
115 ::waitpid(cpid,&status,0);
116 if (WIFEXITED(status)){
117 args.m_exit_code = WEXITSTATUS(status);
121 exec_status = ProcessExecArgs::ExecStatus::AbnormalExit;
123 close(pipefd_out[0]);
126 args.m_output_bytes.
add(
'\0');