src/process.h

Wed, 19 Feb 2025 18:14:12 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 19 Feb 2025 18:14:12 +0100
changeset 35
d75805c1e3b9
parent 4
82680ce258d6
permissions
-rw-r--r--

fix "1 commits" fixes #601

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
3
c87bde92805f add repository scanner
Mike Becker <universe@uap-core.de>
parents: 2
diff changeset
33 class process final {
4
82680ce258d6 add automatic pull/udate of repositories
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
34 std::string m_path = "/bin/false";
82680ce258d6 add automatic pull/udate of repositories
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
35 std::string m_dir = ".";
2
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 std::string m_output;
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 public:
4
82680ce258d6 add automatic pull/udate of repositories
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
38 void setbin(std::string path);
82680ce258d6 add automatic pull/udate of repositories
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
39 void chdir(std::string path);
2
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40
4
82680ce258d6 add automatic pull/udate of repositories
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
41 [[nodiscard]] int exec(std::vector<std::string> args, bool capture = false);
82680ce258d6 add automatic pull/udate of repositories
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
42 [[nodiscard]] int exec_log(std::vector<std::string> args) {
82680ce258d6 add automatic pull/udate of repositories
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
43 return exec(std::move(args), true);
82680ce258d6 add automatic pull/udate of repositories
Mike Becker <universe@uap-core.de>
parents: 3
diff changeset
44 }
2
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 [[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
46 };
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 }
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49
7384ebae6b7c add utility to spawn processes and retrieve their output
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 #endif //PROCESS_H

mercurial