* to complete, returning the exit status.
*
* A thread-safe [1] version of popen() (type="r", to read from the child):
- * Subprocess proc(cmd, Subprocess::pipeStdout());
+ * Subprocess proc(cmd, Subprocess::Options().pipeStdout());
* // read from proc.stdoutFd()
* proc.wait();
*
* A thread-safe [1] version of popen() (type="w", to write to the child):
- * Subprocess proc(cmd, Subprocess::pipeStdin());
+ * Subprocess proc(cmd, Subprocess::Options().pipeStdin());
* // write to proc.stdinFd()
* proc.wait();
*
#endif
};
- static Options pipeStdin() { return Options().stdinFd(PIPE); }
- static Options pipeStdout() { return Options().stdoutFd(PIPE); }
- static Options pipeStderr() { return Options().stderrFd(PIPE); }
-
// Non-copiable, but movable
Subprocess(const Subprocess&) = delete;
Subprocess& operator=(const Subprocess&) = delete;
// Test where the exec call fails() with pipes
checkFdLeak([] {
try {
- Subprocess proc(std::vector<std::string>({"/no/such/file"}),
- Subprocess::pipeStdout().stderrFd(Subprocess::PIPE));
+ Subprocess proc(
+ std::vector<std::string>({"/no/such/file"}),
+ Subprocess::Options().pipeStdout().stderrFd(Subprocess::PIPE));
ADD_FAILURE() << "expected an error when running /no/such/file";
} catch (const SubprocessSpawnError& ex) {
EXPECT_EQ(ENOENT, ex.errnoValue());
}
TEST(PopenSubprocessTest, PopenRead) {
- Subprocess proc("ls /", Subprocess::pipeStdout());
+ Subprocess proc("ls /", Subprocess::Options().pipeStdout());
int found = 0;
gen::byLine(File(proc.stdoutFd())) |
[&] (StringPiece line) {
}
TEST(CommunicateSubprocessTest, SimpleRead) {
- Subprocess proc(std::vector<std::string>{ "/bin/echo", "-n", "foo", "bar"},
- Subprocess::pipeStdout());
+ Subprocess proc(
+ std::vector<std::string>{"/bin/echo", "-n", "foo", "bar"},
+ Subprocess::Options().pipeStdout());
auto p = proc.communicate();
EXPECT_EQ("foo bar", p.first);
proc.waitChecked();
"-e", "s/a test/a successful test/",
"-e", "/^another line/w/dev/stderr",
});
- auto options = Subprocess::pipeStdin().pipeStdout().pipeStderr().usePath();
+ auto options =
+ Subprocess::Options().pipeStdin().pipeStdout().pipeStderr().usePath();
Subprocess proc(cmd, options);
auto out = proc.communicateIOBuf(std::move(input));
proc.waitChecked();
int wcount = 0;
int rcount = 0;
- auto options = Subprocess::pipeStdin().pipeStdout().pipeStderr().usePath();
+ auto options =
+ Subprocess::Options().pipeStdin().pipeStdout().pipeStderr().usePath();
std::vector<std::string> cmd {
"sed",
"-u",