src/process.h

Tue, 21 Jan 2025 18:25:59 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 21 Jan 2025 18:25:59 +0100
changeset 2
7384ebae6b7c
child 3
c87bde92805f
permissions
-rw-r--r--

add utility to spawn processes and retrieve their output

2
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /* Copyright 2025 Mike Becker. All rights reserved.
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 *
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 * Redistribution and use in source and binary forms, with or without
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * modification, are permitted provided that the following conditions are met:
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * 1. Redistributions of source code must retain the above copyright
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * notice, this list of conditions and the following disclaimer.
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 2. Redistributions in binary form must reproduce the above copyright
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer in the
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 * documentation and/or other materials provided with the distribution.
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 *
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 */
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 #ifndef PROCESS_H
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 #define PROCESS_H
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 #include <string>
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include <vector>
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 namespace fm {
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 class process {
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 std::string m_path;
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 std::string m_output;
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 public:
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 explicit process(std::string path);
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 ~process() = default;
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 [[nodiscard]] bool exec(std::vector<std::string> args);
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 [[nodiscard]] const std::string &output() const;
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 };
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 }
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 #endif //PROCESS_H

mercurial