|
Boost : |
Subject: Re: [boost] [gsoc] Boost.Process done
From: Ilya Sokolov (ilyasokol_at_[hidden])
Date: 2010-09-10 19:31:19
On Sat, 11 Sep 2010 00:21:48 +0200
"Boris Schaeling" <boris_at_[hidden]> wrote:
> On Fri, 10 Sep 2010 01:33:53 +0200, Ilya Sokolov
> <ilyasokol_at_[hidden]> wrote:
>
> > [...]The following should solve problems that I know of:
> >
> > typedef std::vector<std::pair<fileno, handle::native_type>>
> > child_streams;
> >
> > typedef boost::function2<
> > std::pair<handle, handle>,
> > fileno,
> > const child_streams&
> > > behavior;
> >
> > std::pair<handle, handle> inherit(fileno fn, const child_streams&)
> > {
> > #ifdef _WIN32
> > handle child_end(GetStdHandle(DWORD(-10-fn)), dont_close);
> > #else
> > handle child_end(fn, dont_close);
> > #endif
> > handle parent_end;
> > return std::make_pair(child_end, parent_end);
> > }
> >
> > class redirect_to
> > {
> > fileno to_;
> > public:
> > redirect_to(fileno to): to_(to) {}
> > std::pair<handle, handle>
> > operator()(fileno fn, const child_streams& cs)
> > {
> > BOOST_ASSERT(fn > to_);
> > child_streams::const_iterator it =
> > // find pair in cs where it->first == to_
> > #ifndef _WIN32
> > handle child_end(posix_dup2(it->second, fn));
> > #else
> > // ...
> > #endif
> > handle parent_end;
> > return std::make_pair(child_end, parent_end);
> > }
> > };
> >enum std_fileno
> > {
> > stdin, stdout, stderr
> > };
> >
> > Example of usage:
> >
> > ctx.stderr = redirect_to(stdout);
>
> I'm a bit confused: If you use fileno like above on Windows
> (0=stdin, 1=stdout and 2=stderr) then we could also use an
> enumeration?
I was thinking about the ability to set behavior of fileno > 2 on posix.
> At least your implementation of inherit makes me think
> so that it's not the file descriptor itself you are interested in but
> only the information whether the standard input, output or error
> stream is configured.
yes
> Then there would be no difference between your
> and mine solution?
???
> [snip]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk