tesseract  5.0.0-alpha-619-ge9db
SVSync Class Reference

The SVSync class provides functionality for Thread & Process Creation. More...

#include <svutil.h>

Static Public Member Functions

static void StartProcess (const char *executable, const char *args)
 Starts a new process. More...
 

Detailed Description

The SVSync class provides functionality for Thread & Process Creation.

Definition at line 36 of file svutil.h.

Member Function Documentation

◆ StartProcess()

void SVSync::StartProcess ( const char *  executable,
const char *  args 
)
static

Starts a new process.

Definition at line 60 of file svutil.cpp.

60  {
61  std::string proc;
62  proc.append(executable);
63  proc.append(" ");
64  proc.append(args);
65  std::cout << "Starting " << proc << std::endl;
66 #ifdef _WIN32
67  STARTUPINFO start_info;
68  PROCESS_INFORMATION proc_info;
69  GetStartupInfo(&start_info);
70  if (!CreateProcess(nullptr, const_cast<char*>(proc.c_str()), nullptr, nullptr, FALSE,
71  CREATE_NO_WINDOW | DETACHED_PROCESS, nullptr, nullptr,
72  &start_info, &proc_info))
73  return;
74 #else
75  int pid = fork();
76  if (pid != 0) { // The father process returns
77  } else {
78 #ifdef __linux__
79  // Make sure the java process terminates on exit, since its
80  // broken socket detection seems to be useless.
81  prctl(PR_SET_PDEATHSIG, 2, 0, 0, 0);
82 #endif
83  char* mutable_args = strdup(args);
84  int argc = 1;
85  for (int i = 0; mutable_args[i]; ++i) {
86  if (mutable_args[i] == ' ') {
87  ++argc;
88  }
89  }
90  std::unique_ptr<char*[]> argv(new char*[argc + 2]);
91  argv[0] = strdup(executable);
92  argv[1] = mutable_args;
93  argc = 2;
94  bool inquote = false;
95  for (int i = 0; mutable_args[i]; ++i) {
96  if (!inquote && mutable_args[i] == ' ') {
97  mutable_args[i] = '\0';
98  argv[argc++] = mutable_args + i + 1;
99  } else if (mutable_args[i] == '"') {
100  inquote = !inquote;
101  mutable_args[i] = ' ';
102  }
103  }
104  argv[argc] = nullptr;
105  execvp(executable, argv.get());
106  free(argv[0]);
107  free(argv[1]);
108  }
109 #endif
110 }

The documentation for this class was generated from the following files:
string
std::string string
Definition: equationdetect_test.cc:21
FALSE
#define FALSE
Definition: capi.h:45