fix: 尝试修复调用命令时抛出异常的问题

fix https://github.com/MaaAssistantArknights/MaaAssistantArknights/issues/1871
This commit is contained in:
MistEO
2022-09-21 23:26:49 +08:00
parent 6fba1bf790
commit 973bea20c4
2 changed files with 11 additions and 5 deletions

View File

@@ -164,7 +164,7 @@ std::string asst::utils::callcmd(const std::string& cmdline)
OVERLAPPED pipeov { .hEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr) };
(void)ReadFile(pipe_parent_read, pipe_buffer.get(), PipeBuffSize, nullptr, &pipeov);
while (1) {
while (true) {
wait_handles.clear();
if (process_running) wait_handles.push_back(process_info.hProcess);
if (!pipe_eof) wait_handles.push_back(pipeov.hEvent);
@@ -181,7 +181,9 @@ std::string asst::utils::callcmd(const std::string& cmdline)
else {
// something bad happened
err = GetLastError();
throw std::system_error(std::error_code(err, std::system_category()));
// throw std::system_error(std::error_code(err, std::system_category()));
Log.error(__FUNCTION__, "A fatal error occurred", err);
break;
}
if (signaled_object == process_info.hProcess) {
@@ -208,7 +210,9 @@ std::string asst::utils::callcmd(const std::string& cmdline)
CloseHandle(process_info.hProcess);
CloseHandle(process_info.hThread);
CloseHandle(pipe_parent_read);
CloseHandle(pipeov.hEvent);
if (pipeov.hEvent) {
CloseHandle(pipeov.hEvent);
}
return pipe_str;
}

View File

@@ -51,7 +51,7 @@ asst::Controller::Controller(AsstCallback callback, void* callback_arg)
fcntl(m_pipe_out[PIPE_READ], F_SETFL, O_NONBLOCK);
if (pipe_in_ret < 0 || pipe_out_ret < 0) {
throw "controller pipe created failed";
Log.error(__FUNCTION__, "controller pipe created failed", pipe_in_ret, pipe_out_ret);
}
m_support_socket = false;
#endif
@@ -293,7 +293,9 @@ std::optional<std::string> asst::Controller::call_command(const std::string& cmd
else {
// something bad happened
err = GetLastError();
throw std::system_error(std::error_code(err, std::system_category()));
// throw std::system_error(std::error_code(err, std::system_category()));
Log.error(__FUNCTION__, "A fatal error occurred", err);
break;
}
if (signaled_object == process_info.hProcess) {