14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/OStringStream.h"
18#include "arcane/utils/Process.h"
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);
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');
void addRange(ConstReferenceType val, Int64 n)
Ajoute n élément de valeur val à la fin du tableau.
void clear()
Supprime les éléments du tableau.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
const T * data() const
Accès à la racine du tableau hors toute protection.
constexpr const_pointer data() const noexcept
Pointeur sur la mémoire allouée.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
@ CanNotFork
Le fork() a échoué
@ CanNotCreatePipe
L'appel à pipe2() a échoué
String command() const
Commande à exécuter. Doit correspondre à un exécutable.
ByteConstArrayView inputBytes() const
Chaîne de caractère à envoyer sur l'entrée standard (STDIN) du processsus.
StringConstArrayView arguments() const
Liste des arguments.
const char * localstr() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
Vecteur 1D de données avec sémantique par valeur (style STL).
ConstArrayView< String > StringConstArrayView
Equivalent C d'un tableau à une dimension de chaînes de caractères.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
ConstArrayView< Byte > ByteConstArrayView
Equivalent C d'un tableau à une dimension de caractères.
unsigned char Byte
Type d'un octet.