| 1544 | } |
| 1545 | |
| 1546 | inline int Popen::wait() noexcept(false) |
| 1547 | { |
| 1548 | #ifdef __USING_WINDOWS__ |
| 1549 | int ret = WaitForSingleObject(process_handle_, INFINITE); |
| 1550 | |
| 1551 | // WaitForSingleObject with INFINITE should only return when process has signaled |
| 1552 | if (ret != WAIT_OBJECT_0) { |
| 1553 | throw OSError("Unexpected return code from WaitForSingleObject", 0); |
| 1554 | } |
| 1555 | |
| 1556 | DWORD dretcode_; |
| 1557 | |
| 1558 | if (FALSE == GetExitCodeProcess(process_handle_, &dretcode_)) |
| 1559 | throw OSError("Failed during call to GetExitCodeProcess", 0); |
| 1560 | |
| 1561 | CloseHandle(process_handle_); |
| 1562 | |
| 1563 | return (int)dretcode_; |
| 1564 | #else |
| 1565 | int ret, status; |
| 1566 | std::tie(ret, status) = util::wait_for_child_exit(pid()); |
| 1567 | if (ret == -1) { |
| 1568 | if (errno != ECHILD) throw OSError("waitpid failed", errno); |
| 1569 | return 0; |
| 1570 | } |
| 1571 | if (WIFEXITED(status)) return WEXITSTATUS(status); |
| 1572 | if (WIFSIGNALED(status)) return WTERMSIG(status); |
| 1573 | else return 255; |
| 1574 | |
| 1575 | return 0; |
| 1576 | #endif |
| 1577 | } |
| 1578 | |
| 1579 | inline int Popen::poll() noexcept(false) |
| 1580 | { |