tesseract v5.3.3.20231005
tesseract::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 38 of file svutil.h.

Member Function Documentation

◆ StartProcess()

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

Starts a new process.

Definition at line 67 of file svutil.cpp.

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

The documentation for this class was generated from the following files: