Václav Kubernát | 6d9357e | 2021-01-28 15:38:24 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 13 | namespace velia::utils { |
| 14 | /** |
Václav Kubernát | e569193 | 2021-02-18 04:05:45 +0100 | [diff] [blame] | 15 | * 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át | 6d9357e | 2021-01-28 15:38:24 +0100 | [diff] [blame] | 18 | * |
| 19 | * @param logger Logger to use. |
Václav Kubernát | de0e4e6 | 2021-02-08 17:46:14 +0100 | [diff] [blame] | 20 | * @param absolutePath Full path to the excutable. |
Václav Kubernát | 6d9357e | 2021-01-28 15:38:24 +0100 | [diff] [blame] | 21 | * @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át | e569193 | 2021-02-18 04:05:45 +0100 | [diff] [blame] | 23 | * @return stdout of the command |
Václav Kubernát | 6d9357e | 2021-01-28 15:38:24 +0100 | [diff] [blame] | 24 | */ |
| 25 | enum class ExecOptions { |
| 26 | DropRoot |
| 27 | }; |
Václav Kubernát | e569193 | 2021-02-18 04:05:45 +0100 | [diff] [blame] | 28 | std::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át | 6d9357e | 2021-01-28 15:38:24 +0100 | [diff] [blame] | 29 | } |