blob: 6384b9d694b724708ce547f46ae7b9b74c599e52 [file] [log] [blame]
Václav Kubernát6d9357e2021-01-28 15:38:24 +01001/*
2 * Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
3 *
4 * Written by Václav Kubernát <kubernat@cesnet.cz>
5 *
6*/
7
8#pragma once
9#include <set>
10#include <string>
11#include "log-fwd.h"
12
13namespace velia::utils {
14/**
Václav Kubernáte5691932021-02-18 04:05:45 +010015 * Spawns a new process with an executable specified by `absolutePath` and waits until it returns. The return value is
16 * the stdout of the process. Throws if the program has a non-zero exit code with a message containing the stderr of the
17 * process.
Václav Kubernát6d9357e2021-01-28 15:38:24 +010018 *
19 * @param logger Logger to use.
Václav Kubernátde0e4e62021-02-08 17:46:14 +010020 * @param absolutePath Full path to the excutable.
Václav Kubernát6d9357e2021-01-28 15:38:24 +010021 * @param args Arguments to pass to the program. Can be {} if no arguments should be passed.
22 * @param std_in stdin input fo the program.
Václav Kubernáte5691932021-02-18 04:05:45 +010023 * @return stdout of the command
Václav Kubernát6d9357e2021-01-28 15:38:24 +010024 */
25enum class ExecOptions {
26 DropRoot
27};
Václav Kubernáte5691932021-02-18 04:05:45 +010028std::string execAndWait(velia::Log logger, const std::string& absolutePath, std::initializer_list<std::string> args, std::string_view std_in, const std::set<ExecOptions> opts = {});
Václav Kubernát6d9357e2021-01-28 15:38:24 +010029}