14#include "arccore/common/internal/Process.h"
16#include "arccore/base/NotImplementedException.h"
17#include "arccore/base/FixedArray.h"
24#ifdef ARCCORE_OS_LINUX
42#ifdef ARCCORE_OS_LINUX
43 args.m_output_bytes.
clear();
50 int r0 = pipe2(pipefd_out, O_CLOEXEC);
53 r0 = pipe2(pipefd_in, O_CLOEXEC);
56 pid_t cpid = ::fork();
67 ::close(STDOUT_FILENO);
68 ::close(pipefd_out[0]);
69 ::dup2(pipefd_out[1], STDOUT_FILENO);
72 ::close(STDIN_FILENO);
73 ::close(pipefd_in[1]);
74 ::dup2(pipefd_in[0], STDIN_FILENO);
83 for (
Integer i = 0; i < nb_arg; ++i)
84 command_args[i + 1] = arguments[i].localstr();
85 command_args[0] = cmd_name;
86 command_args[nb_arg + 1] =
nullptr;
88 const char*
const newenviron[] = { NULL };
89 ::execve(cmd_name, (
char*
const*)command_args.
data(), (
char*
const*)newenviron);
93 ::close(pipefd_out[1]);
94 ::close(pipefd_in[0]);
96 Int64 nb_wanted_write = input_bytes.
size();
97 Int64 nb_written = ::write(pipefd_in[1], input_bytes.
data(), nb_wanted_write);
98 if (nb_written != nb_wanted_write)
99 std::cerr <<
"Error writing to pipe\n";
100 ::close(pipefd_in[1]);
101 const int BUF_SIZE = 4096;
103 buf[BUF_SIZE] =
'\0';
104 Int32 max_iteration = 1000000;
105 Int32 current_iteration = 0;
107 for (
Int32 i = 0; i < max_iteration; ++i) {
108 ssize_t nb_read = ::read(pipefd_out[0], buf.data(), BUF_SIZE);
109 if (nb_read == EINTR)
113 Int32 i_nb_read =
static_cast<Int32>(nb_read);
114 buf[i_nb_read] =
'\0';
115 args.m_output_bytes.
addRange(buf.
view().subView(0, i_nb_read));
123 child_pid = ::waitpid(cpid, &status, 0);
124 }
while (child_pid == -1 && errno == EINTR);
126 if (WIFEXITED(status)) {
127 args.m_exit_code = WEXITSTATUS(status);
131 exec_status = ProcessExecArgs::ExecStatus::AbnormalExit;
133 close(pipefd_out[0]);
136 args.m_output_bytes.
add(
'\0');
void clear()
Supprime les éléments du tableau.
const T * data() const
Accès à la racine du tableau hors toute protection.
void addRange(ConstReferenceType val, Int64 n)
Ajoute n élément de valeur val à la fin du tableau.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
Vue constante d'un tableau de type T.
constexpr const_pointer data() const noexcept
Pointeur sur la mémoire allouée.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
Tableau 1D de taille fixe.
constexpr __host__ __device__ ArrayView< T > view()
Vue modifiable sur le tableau.
Exception lorsqu'une fonction n'est pas implémentée.
@ CanNotFork
Le fork() a échoué
@ CanNotCreatePipe
L'appel à pipe2() a échoué
ConstArrayView< String > arguments() const
Liste des arguments.
String command() const
Commande à exécuter. Doit correspondre à un exécutable.
ConstArrayView< Byte > inputBytes() const
Chaîne de caractères à envoyer sur l'entrée standard (STDIN) du processsus.
static ProcessExecArgs::ExecStatus execute(ProcessExecArgs &args)
Exécute un processus dont les infos sont contenues dans args.
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).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
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.
std::int32_t Int32
Type entier signé sur 32 bits.