diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2016-09-10 14:13:19 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2016-09-10 14:13:19 +0300 |
commit | 985f1dde6afa6a42149118e6085325eacb1bd53e (patch) | |
tree | 9f0234366c61cc5c7fb60c6194350eb54909ba0d | |
parent | 3aba9af9e68f22ab6291fc16986a215f3f75508d (diff) |
Add sample usage with process to fdstream as a comment
-rw-r--r-- | butl/fdstream | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/butl/fdstream b/butl/fdstream index 990cea0..bb5364b 100644 --- a/butl/fdstream +++ b/butl/fdstream @@ -182,6 +182,64 @@ namespace butl // Note that ifdstream destructor will close an open file descriptor but // will ignore any errors. To detect such errors, call close() explicitly. // + // This is a sample usage of iofdstreams with process. Note that here it is + // expected that the child process reads from STDIN first and writes to + // STDOUT afterwards. + // + // try + // { + // process pr (args, -1, -1); + // + // try + // { + // // In case of exception, skip and close input after output. + // // + // ifdstream is (pr.in_ofd, fdstream_mode::skip); + // ofdstream os (pr.out_fd); + // + // // Write. + // + // os.close (); // Don't block the other end. + // + // // Read. + // + // is.close (); // Skip till end and close. + // + // if (pr.wait ()) + // { + // return ...; // Good. + // } + // + // // Non-zero exit, diagnostics presumably issued, fall through. + // } + // catch (const failure&) + // { + // // IO failure, child exit status doesn't matter. Just wait for the + // // process completion and fall through. + // // + // // Note that this is optional if the process_error handler simply + // // falls through since process destructor will wait (but will ignore + // // any errors). + // // + // pr.wait (); + // } + // + // error << .... ; + // + // // Fall through. + // } + // catch (const process_error& e) + // { + // error << ... << e.what (); + // + // if (e.child ()) + // exit (1); + // + // // Fall through. + // } + // + // throw failed (); + // class LIBBUTL_EXPORT ifdstream: fdstream_base, public std::istream { public: |