Daten aus boost::iostreams::stream lesen
-
Hallo,
ich bin ein bisschen am verzweifeln. Es geht um boost iostreams in Verbindung mit boost process.
Im Grunde suche ich nur eine (weitere) Möglichkeit Daten aus einem boost::iostream::stream auszulesen.
Unten im Code habe ich meinen Alternative Ansatz reingeschrieben.
Bei diesem hängt sich das Projekt jedoch auf.
Leider werde ich aus der boost Dokumentation nicht ganz schlau.http://www.boost.org/doc/libs/1_43_0/libs/iostreams/doc/functions/read.html
#include <boost/process/mitigate.hpp> #include <boost/process.hpp> #include <boost/iostreams/device/file_descriptor.hpp> #include <boost/iostreams/stream.hpp> #include <boost/filesystem.hpp> #include <string> #include <vector> #include <iostream> int main(int argc, char** argv) { namespace bp = ::boost::process; namespace bpi = boost::process::initializers; namespace bio = boost::iostreams; boost::process::pipe p = boost::process::create_pipe(); bio::file_descriptor_sink sink(p.sink, bio::close_handle); boost::system::error_code ec; bp::child c = bp::execute( bpi::run_exe(boost::filesystem::path("test.exe")), bpi::set_on_error(ec), bpi::bind_stdout(sink) ); bp::wait_for_exit(c); bio::file_descriptor_source source(p.source, bio::close_handle); bio::stream<bio::file_descriptor_source> is(source); std::string s; std::getline(is, s); // Alterantive zu diesem std::getline? // ---- Alternative ---- // char data[100]; // std::streamsize read = bio::read(is, &data[0], 100); std::cout << s << std::endl; return 0; }
-
Ich habs rausgefunden. Damit funktioniert alles wie gewünscht.
std::streamsize read = bio::read(p.source /* hier direkt die source und nicht den stream angeben*/, &data[0], 100);