Jlm
Program.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2025 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #include <jlm/util/common.hpp>
7 #include <jlm/util/Program.hpp>
8 
9 #include <spawn.h>
10 #include <sys/wait.h>
11 
12 extern char ** environ;
13 
14 namespace jlm::util
15 {
16 
17 int
19  const std::string & programName,
20  const std::vector<std::string> & programArguments)
21 {
22  std::vector<char *> arguments;
23  arguments.push_back(const_cast<char *>(programName.c_str()));
24  for (const auto & argument : programArguments)
25  {
26  arguments.push_back(const_cast<char *>(argument.c_str()));
27  }
28  arguments.push_back(nullptr);
29 
30  pid_t pid = -1;
31  int status = posix_spawnp(&pid, programName.c_str(), nullptr, nullptr, arguments.data(), environ);
32  if (status != 0)
33  {
34  return EXIT_FAILURE;
35  }
36 
37  waitpid(pid, &status, 0);
38  return EXIT_SUCCESS;
39 }
40 
41 std::string
43 {
44  return "xdot";
45 }
46 
47 }
char ** environ
std::string getDotViewer()
Definition: Program.cpp:42
int executeProgramAndWait(const std::string &programName, const std::vector< std::string > &programArguments)
Definition: Program.cpp:18