| 395 | } |
| 396 | |
| 397 | void process::read(const writer& output) const |
| 398 | { |
| 399 | #ifdef _WIN32 |
| 400 | // clang-format off |
| 401 | constexpr std::string_view filename = "stdout"; |
| 402 | auto tmp = tmp_dir{}; |
| 403 | HANDLE handle = CreateFile((tmp.path / filename).string().c_str(), |
| 404 | GENERIC_READ | GENERIC_WRITE, |
| 405 | 0, |
| 406 | nullptr, |
| 407 | CREATE_ALWAYS, |
| 408 | FILE_ATTRIBUTE_NORMAL, |
| 409 | nullptr); |
| 410 | impl->check_exec(impl->command, impl->cwd.string(), impl->args, impl->envs, |
| 411 | handle == nullptr or handle == INVALID_HANDLE_VALUE ? |
| 412 | GetStdHandle(STD_OUTPUT_HANDLE) : handle); |
| 413 | CloseHandle(handle); |
| 414 | handle = CreateFile((tmp.path / filename).string().c_str(), |
| 415 | GENERIC_READ | GENERIC_WRITE, |
| 416 | 0, |
| 417 | nullptr, |
| 418 | OPEN_EXISTING, |
| 419 | FILE_ATTRIBUTE_NORMAL, |
| 420 | nullptr); |
| 421 | if(handle == nullptr or handle == INVALID_HANDLE_VALUE) |
| 422 | MIGRAPHX_THROW("Unable to open file: " + (tmp.path / filename)); |
| 423 | auto size = GetFileSize(handle, nullptr); |
| 424 | std::string result(size, '\0'); |
| 425 | if(ReadFile(handle, result.data(), size, nullptr, nullptr) == FALSE) |
| 426 | MIGRAPHX_THROW("Failed reading file: " + (tmp.path / filename)); |
| 427 | CloseHandle(handle); |
| 428 | // clang-format on |
| 429 | #else |
| 430 | std::stringstream ss; |
| 431 | impl->check_exec(impl->get_command(), redirect_to(ss)); |
| 432 | auto result = ss.str(); |
| 433 | #endif |
| 434 | output(result.data(), result.size()); |
| 435 | } |
| 436 | |
| 437 | void process::exec() |
| 438 | { |
no test coverage detected