|
Boost : |
Subject: Re: [boost] How to bind program termination with end-of-stream in Boost.Process 0.5?
From: alfC (alfredo.correa_at_[hidden])
Date: 2012-09-12 16:10:12
On Wed, Sep 12, 2012 at 12:12 PM, Boris Schaeling [via Boost]
<ml-node+s2283326n4635662h0_at_[hidden]> wrote:
> On Sun, 09 Sep 2012 02:00:06 +0200, alfC <[hidden email]> wrote:
>
> Hi Alfredo,
>
> thanks for your question! Good to see that people start using the new
> version. :)
no, thanks to you for the library.
I have a small criticism (probably from ignorance) and it is that the
new version seems to be more complicated to use than the previous
versions.
>
>> [...]One can make a look to read the output of the process until the
>> program
>> finishes, but the stream is not invalid after program termination.
>> ...
>> while(std::getline(is, s)){ // is is an stream associated with a
>> process
>> (e.g. '/usr/bin/ls')
>> std::cout << "read: " << s << std::endl;
>> }
>> std::clog << "end" << std::endl; // never reach
>> ...
>
> Is "is" a Boost.Iostreams stream?
"is" is a boost::iostreams::stream<file_descriptor_source>, like in
the examples, do I have another option? (e.g. to simplify the number
of layers)
The full example that does not work for me is this, message continues below:
#include <boost/process.hpp> // version 0.5 from
http://www.highscore.de/boost/process0.5/process.zip
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/stream.hpp>
#include <string>
using namespace boost::process;
using namespace boost::process::initializers;
using namespace boost::iostreams;
int main(){
boost::process::pipe p = create_pipe();
file_descriptor_sink sink(p.sink, close_handle);
child c = execute(run_exe("/usr/bin/ls"), bind_stdout(sink));
file_descriptor_source source(p.source, close_handle);
stream<file_descriptor_source> is(source);
std::string s;
while(std::getline(is, s)){
std::cout << "read: " << s << std::endl;
}
std::clog << "end" << std::endl; // never reach
}
If so, do you use Boost 1.50.0 or an
> earlier version? Then I strongly recommend upgrading to Boost 1.51.0.
actually I am using 1.48 (default in fedora 17).
> Various end-of-stream unit tests failed when I used Boost 1.50.0 because
> of a bug in Boost.Iostreams.
If that is the case you can add a warning in the library to not
compile with old versions of boost.
someone at stackoverflow, suggested to open the process asynchronously
and do a status check.
(see http://stackoverflow.com/questions/12329065/how-to-bind-program-termination-with-end-of-stream-in-boost-process-0-5)
Seemed like an ovekill. I am glad it is a bug instead.
Thank you very much.
Alfredo
-- View this message in context: http://boost.2283326.n4.nabble.com/How-to-bind-program-termination-with-end-of-stream-in-Boost-Process-0-5-tp4635497p4635668.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk