ref: refs/heads/ma-misc
commit a0683490efeff432f52582934dc7f44ef8890240
Author: Michael Andres
Date: Thu Jul 23 10:10:39 2009 +0200
ExternalProgram: add command output redirection to stream.
---
zypp/ExternalProgram.cc | 9 +++++++++
zypp/ExternalProgram.h | 22 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/zypp/ExternalProgram.cc b/zypp/ExternalProgram.cc
index 8da0779..22979d0 100644
--- a/zypp/ExternalProgram.cc
+++ b/zypp/ExternalProgram.cc
@@ -483,4 +483,13 @@ namespace zypp {
}
}
+ std::ostream & ExternalProgram::operator>>( std::ostream & out_r )
+ {
+ setBlocking( true );
+ for ( std::string line = receiveLine(); line.length(); line = receiveLine() )
+ out_r << line;
+ return out_r;
+ }
+
+
} // namespace zypp
diff --git a/zypp/ExternalProgram.h b/zypp/ExternalProgram.h
index 305e03f..f33a6d6 100644
--- a/zypp/ExternalProgram.h
+++ b/zypp/ExternalProgram.h
@@ -168,6 +168,28 @@ namespace zypp {
*/
static void renumber_fd (int origfd, int newfd);
+ public:
+
+ /**
+ * Redirect all command output to an \c ostream.
+ * Returns when the command has completed.
+ * \code
+ * std::ostringstream s;
+ * ExternalProgram("pwd") >> s;
+ * SEC << s.str() << endl;
+ * \endcode
+ * \code
+ * std::ostringstream s;
+ * ExternalProgram prog("ls -l wrzl");
+ * prog >> s;
+ * if ( prog.close() == 0 )
+ * MIL << s.str() << endl;
+ * else
+ * ERR << prog.execError() << endl;
+ * \endcode
+ */
+ std::ostream & operator>>( std::ostream & out_r );
+
protected:
int checkStatus( int );
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org