MCPcopy Create free account
hub / github.com/MeisApps/pcbu-desktop / RunUserCommand

Method RunUserCommand

common/src/shell/Shell.cpp:60–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60ShellCmdResult Shell::RunUserCommand(const std::string &cmd) {
61#ifdef WINDOWS
62 boost::process::v1::ipstream outStream{};
63 boost::process::v1::ipstream errStream{};
64 boost::process::v1::child proc(fmt::format("{0} {1} \"{2}\"", SHELL_NAME, SHELL_CMD_ARG, cmd), boost::process::v1::std_out > outStream,
65 boost::process::v1::std_err > errStream, boost::process::v1::windows::create_no_window);
66 std::string output{};
67 std::string line{};
68 while(outStream && std::getline(outStream, line) && !line.empty())
69 output.append(line + "\n");
70 while(errStream && std::getline(errStream, line) && !line.empty())
71 output.append(line + "\n");
72 proc.wait();
73#else
74 boost::asio::io_context ctx{};
75 boost::asio::readable_pipe pipe{ctx};
76 boost::process::v2::process proc(ctx, boost::process::v2::environment::find_executable(SHELL_NAME), {SHELL_CMD_ARG, cmd},
77 boost::process::v2::process_stdio{{}, pipe, pipe}
78
79#ifdef WINDOWS
80 ,
81 boost::process::v2::windows::process_creation_flags<CREATE_NO_WINDOW>{}
82#endif
83 );
84
85 std::string output{};
86 boost::system::error_code ec;
87 boost::asio::read(pipe, boost::asio::dynamic_buffer(output), ec);
88 proc.wait();
89#endif
90
91 spdlog::debug("Process exit. Code: {} Command: '{}' Output: '{}'", proc.exit_code(), cmd, StringUtils::Trim(output));
92 auto result = ShellCmdResult();
93 result.exitCode = proc.exit_code();
94 result.output = output;
95 return result;
96}
97
98void Shell::SpawnCommand(const std::string &cmd) {
99#ifdef WINDOWS

Callers

nothing calls this directly

Calls 1

ShellCmdResultClass · 0.85

Tested by

no test coverage detected