Skip to content

Source · fairmq/tools/

Process.hpublic header

Defines struct fair::mq::tools::execute_result.

Described in Helpers in fair::mq::tools.

fairmq/tools/Process.h53 lines · C++API: execute_resultGitHub ↗
1/********************************************************************************2 *    Copyright (C) 2017 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH    *3 *                                                                              *4 *              This software is distributed under the terms of the             *5 *              GNU Lesser General Public Licence (LGPL) version 3,             *6 *                  copied verbatim in the file "LICENSE"                       *7 ********************************************************************************/8 9#ifndef FAIR_MQ_TOOLS_PROCESS_H10#define FAIR_MQ_TOOLS_PROCESS_H11 12#include <chrono>13#include <string>14 15namespace fair::mq::tools16{17 18/**19 * Result type for execute function. Holds captured stdout output and exit code.20 */21struct execute_result22{23    std::string console_out;24    int exit_code;25};26 27/**28 * Execute given command in forked process and capture stdout output29 * and exit code.30 *31 * @param[in] cmd Command to execute32 * @param[in] prefix How to prefix each captured output line with33 * @param[in] input Data which is sent to stdin of the child process34 * @return Captured stdout output and exit code35 */36execute_result execute(const std::string& cmd,37                       const std::string& prefix = "",38                       const std::string& input = "",39                       int sig = -1);40 41/**42 * Same as above, but kill the child process (SIGKILL) if it runs longer than43 * timeout. A timeout of zero means no limit.44 */45execute_result execute(const std::string& cmd,46                       const std::string& prefix,47                       const std::string& input,48                       int sig,49                       std::chrono::milliseconds timeout);50 51} // namespace fair::mq::tools52 53#endif /* FAIR_MQ_TOOLS_PROCESS_H */