Boost logo

Boost Users :

Subject: [Boost-users] asio::posix::stream_descriptor throws with redirected stdin
From: Chris Stankevitz (chrisstankevitz_at_[hidden])
Date: 2012-09-04 00:12:19


Hello,

Please consider the program listed below. I compiled with the command
"g++ test.cpp -lboost_system-mt" using GCC 4.5 on Gentoo linux with
boost 1.48.

When I invoke the program like this it works fine:
cat test.cpp | ./a.out

When I invoke the program like this it throws:
./a.out < test.cpp

The exception thrown:
terminate called after throwing an instance of
'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error>
>'
  what(): assign: Operation not permitted
Aborted

Question: Why does the program throw when I redirect stdin to point to a file?

Thank you,

Chris

//=== begin test.cpp ===

#include <boost/asio.hpp>

int main()
{
  boost::asio::io_service IoService;

  int Fd = ::dup(STDIN_FILENO);

  boost::asio::posix::stream_descriptor Stream(IoService, Fd);

  return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net