MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / run_process

Function run_process

app/workflow/workflow.cpp:353–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

351 std::ostringstream out;
352 out << program;
353 for (const std::string & arg : args) {
354 out << ' ' << arg;
355 }
356 return out.str();
357}
358
359int run_process(const std::string & program, const std::vector<std::string> & args) {
360#if defined(_WIN32)
361 std::vector<std::wstring> wide_args;
362 wide_args.reserve(args.size() + 1);
363 wide_args.push_back(std::filesystem::path(program).wstring());
364 for (const std::string & arg : args) {
365 wide_args.push_back(std::filesystem::path(arg).wstring());
366 }
367
368 std::vector<const wchar_t *> argv;
369 argv.reserve(wide_args.size() + 1);
370 for (const std::wstring & arg : wide_args) {
371 argv.push_back(arg.c_str());
372 }
373 argv.push_back(nullptr);
374
375 const intptr_t rc = _wspawnvp(_P_WAIT, wide_args.front().c_str(), argv.data());
376 if (rc == -1) {
377 throw std::runtime_error(
378 "failed to launch process: " + format_process_args(program, args) + ": " + std::strerror(errno));
379 }
380 return static_cast<int>(rc);
381#elif defined(__EMSCRIPTEN__)
382 throw std::runtime_error("external processes are unavailable in the browser: " + format_process_args(program, args));
383#else
384 std::vector<char *> argv;
385 argv.reserve(args.size() + 2);
386 argv.push_back(const_cast<char *>(program.c_str()));
387 for (const std::string & arg : args) {
388 argv.push_back(const_cast<char *>(arg.c_str()));
389 }
390 argv.push_back(nullptr);
391
392 pid_t pid = 0;
393 const int spawn_rc = posix_spawnp(&pid, program.c_str(), nullptr, nullptr, argv.data(), environ);
394 if (spawn_rc != 0) {
395 throw std::runtime_error(
396 "failed to launch process: " + format_process_args(program, args) + ": " + std::strerror(spawn_rc));
397 }
398
399 int status = 0;
400 while (waitpid(pid, &status, 0) < 0) {
401 if (errno != EINTR) {
402 throw std::runtime_error("failed waiting for process: " + program + ": " + std::strerror(errno));
403 }
404 }
405 if (WIFEXITED(status)) {
406 return WEXITSTATUS(status);
407 }
408 if (WIFSIGNALED(status)) {

Callers 1

run_convert_audio_stepFunction · 0.85

Calls 3

format_process_argsFunction · 0.85
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected