Boost logo

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-17 22:29:37


On Sun, Sep 16, 2012 at 11:54 AM, Boris Schaeling [via Boost]
<ml-node+s2283326n4635834h32_at_[hidden]> wrote:
> On Sun, 16 Sep 2012 05:29:29 +0200, alfC <[hidden email]> wrote:
>
>> [...]ok, thanks for the info. Is that a question for me? I am not
>> familiar
>> with these objects. Also I use Linux only for development. These
>> objects didn't seem to be necessary in Boost.Process GSOC2010.
>
> That's true (I see you are familiar with previous versions :). We had a
> handle type which was defined by Boost.Process. We also had stream types
> like pistream and postream.
> All of this has been replaced with types from
> Boost.Iostreams. We could still define all of this in Boost.Process
> theoretically. But I think it makes more sense if we reuse other Boost
> libraries and concentrate in Boost.Process on what that library really is
> about (especially after working on it for six years ;).

I guess it is not not late to provide "convenience"
pistream/postream/piostream classes that wrap up all the complexity.

boost::pistream pis("/bin/ls");
for(std::string line; std::getline(pis, line); ){
   std::cout << "line: " << line << std::endl;
}
std::cout << "end" << std::endl;

>
>> [...]ok, since there is no conclusive solution, so maybe to end this
>> thread
>> let me file this as a possible bug (or confirm it is the expected
>> behavior), the symptom is that the program never ends (linux, fedora
>> 17, boost 1.48):
>
> Can you try this program? It works for me:

Thanks, the program worked (boost 1.48) and I posted the solution in
stakoverflow: http://stackoverflow.com/a/12469478/225186
I don't have any idea why this works vs. the other. I wonder if I have
to do the same for doing output to the process.

Thanks,
Alfredo

> -----
> #include <boost/process.hpp>
> #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);
> execute(run_exe("/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;
> }
> -----
>
> Boris
>
>> [...]
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://boost.2283326.n4.nabble.com/How-to-bind-program-termination-with-end-of-stream-in-Boost-Process-0-5-tp4635497p4635834.html
> To unsubscribe from How to bind program termination with end-of-stream in
> Boost.Process 0.5?, click here.
> NAML

-- 
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-tp4635497p4635913.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