Codemod: use #include angle brackets in folly and thrift
[folly.git] / folly / Subprocess.h
index d3a9fb8ec5240b206845ca52b97ec5e378440249..e1fed9f7beb6a1ef4c4a28309f7b6a9354047840 100644 (file)
 #include <boost/operators.hpp>
 #include <boost/noncopyable.hpp>
 
-#include "folly/io/IOBufQueue.h"
-#include "folly/MapUtil.h"
-#include "folly/Portability.h"
-#include "folly/Range.h"
+#include <folly/io/IOBufQueue.h>
+#include <folly/MapUtil.h>
+#include <folly/Portability.h>
+#include <folly/Range.h>
 
 namespace folly {
 
@@ -264,6 +264,11 @@ class Subprocess : private boost::noncopyable {
      */
     Options& usePath() { usePath_ = true; return *this; }
 
+    /**
+     * Change the child's working directory, after the vfork.
+     */
+    Options& chdir(const std::string& dir) { childDir_ = dir; return *this; }
+
 #if __linux__
     /**
      * Child will receive a signal when the parent exits.
@@ -284,6 +289,7 @@ class Subprocess : private boost::noncopyable {
     FdMap fdActions_;
     bool closeOtherFds_;
     bool usePath_;
+    std::string childDir_;  // "" keeps the parent's working directory
 #if __linux__
     int parentDeathSignal_{0};
 #endif
@@ -335,12 +341,15 @@ class Subprocess : private boost::noncopyable {
    * If stdout or stderr is not a pipe, an empty IOBuf queue will be returned
    * for the respective buffer.
    *
-   * Note that communicate() returns when all pipes to/from the child are
-   * closed; the child might stay alive after that, so you must still wait().
+   * Note that communicate() and communicateIOBuf() both return when all
+   * pipes to/from the child are closed; the child might stay alive after
+   * that, so you must still wait().
+   *
+   * communicateIOBuf() uses IOBufQueue for buffering (which has the
+   * advantage that it won't try to allocate all data at once), but it does
+   * store the subprocess's entire output in memory before returning.
    *
-   * communicateIOBuf uses IOBufQueue for buffering (which has the advantage
-   * that it won't try to allocate all data at once).  communicate
-   * uses strings for simplicity.
+   * communicate() uses strings for simplicity.
    */
   std::pair<IOBufQueue, IOBufQueue> communicateIOBuf(
       IOBufQueue input = IOBufQueue());