| 44 | } |
| 45 | |
| 46 | size_t TPipeInput::DoRead(void* buf, size_t len) { |
| 47 | if (Impl_->Pipe_ == nullptr) { |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | size_t bytesRead = ::fread(buf, 1, len, Impl_->Pipe_); |
| 52 | if (bytesRead == 0) { |
| 53 | int exitStatus = ::pclose(Impl_->Pipe_); |
| 54 | Impl_->Pipe_ = nullptr; |
| 55 | if (exitStatus == -1) { |
| 56 | ythrow TSystemError() << "pclose() failed"; |
| 57 | } else if (exitStatus != 0) { |
| 58 | ythrow yexception() << "subprocess exited with non-zero status(" << exitStatus << ")"; |
| 59 | } |
| 60 | } |
| 61 | return bytesRead; |
| 62 | } |
| 63 | |
| 64 | TPipeOutput::TPipeOutput(const TString& command) |
| 65 | : TPipeBase(command, "w") |