コード例 #1
0
void test_input() 
{ 
    std::vector<std::string> args; 
    args.push_back("helpers"); 
    args.push_back("stdin-to-stdout"); 

    bp::posix_context ctx; 
    ctx.input_behavior.insert(bp::behavior_map::value_type(STDIN_FILENO, bp::capture_stream())); 
    ctx.output_behavior.insert(bp::behavior_map::value_type(STDOUT_FILENO, bp::capture_stream())); 
    ctx.environment = bp::self::get_environment(); 

    bp::posix_child c = bp::posix_launch(get_helpers_path(), args, ctx); 

    bp::postream &os = c.get_input(STDIN_FILENO); 
    bp::pistream &is = c.get_output(STDOUT_FILENO); 

    os << "message-to-process" << std::endl; 
    os.close(); 

    std::string word; 
    is >> word; 
    BOOST_CHECK_EQUAL(word, "message-to-process"); 

    const bp::status s = c.wait(); 
    BOOST_REQUIRE(s.exited()); 
    BOOST_CHECK_EQUAL(s.exit_status(), EXIT_SUCCESS); 
} 
コード例 #2
0
void check_redirect(int desc1, int desc2, const std::string &msg) 
{ 
    std::vector<std::string> args; 
    args.push_back("helpers"); 
    args.push_back("posix-echo-two"); 
    args.push_back(boost::str(boost::format("%1%") % desc1)); 
    args.push_back(boost::str(boost::format("%1%") % desc2)); 
    args.push_back(msg); 

    bp::posix_context ctx; 
    ctx.output_behavior.insert(bp::behavior_map::value_type(desc1, bp::capture_stream())); 
    ctx.output_behavior.insert(bp::behavior_map::value_type(desc2, bp::posix_redirect_stream(desc1))); 
    ctx.environment = bp::self::get_environment(); 

    bp::posix_child c = posix_launch(get_helpers_path(), args, ctx); 

    bp::pistream &is = c.get_output(desc1); 
    int dtmp; 
    std::string word; 
    is >> dtmp; 
    BOOST_CHECK_EQUAL(dtmp, desc1); 
    is >> word; 
    BOOST_CHECK_EQUAL(word, msg); 
    is >> dtmp; 
    BOOST_CHECK_EQUAL(dtmp, desc2); 
    is >> word; 
    BOOST_CHECK_EQUAL(word, msg); 

    const bp::status s = c.wait(); 
    BOOST_REQUIRE(s.exited()); 
    BOOST_CHECK_EQUAL(s.exit_status(), EXIT_SUCCESS); 
} 
コード例 #3
0
ファイル: wait.cpp プロジェクト: bytemaster/mace
void start_child(const std::string &sec) 
{ 
    std::vector<std::string> args; 
    args.push_back("wait-exit"); 
    args.push_back(sec); 

    bp::child c = bp::create_child(get_helpers_path(), args); 
    int exit_code = c.wait(); 
#if defined(BOOST_POSIX_API) 
    BOOST_REQUIRE(WIFEXITED(exit_code)); 
    BOOST_CHECK_EQUAL(WEXITSTATUS(exit_code), EXIT_SUCCESS); 
#elif defined(BOOST_WINDOWS_API) 
    BOOST_CHECK_EQUAL(exit_code, EXIT_SUCCESS); 
#endif 
} 
コード例 #4
0
    bp::child operator()(const std::vector<std::string> args, 
               bp::context ctx, 
               bp::stream_behavior bstdin = bp::close_stream(), 
               bp::stream_behavior bstdout = bp::close_stream(), 
               bp::stream_behavior bstderr = bp::close_stream(), 
               bool usein = false) 
        const 
    { 
        ctx.stdin_behavior = bstdin; 
        ctx.stdout_behavior = bstdout; 
        ctx.stderr_behavior = bstderr; 

        if (ctx.environment.empty()) 
            ctx.environment = bp::self::get_environment(); 

        return bp::launch(get_helpers_path(), args, ctx); 
    } 
コード例 #5
0
    bp::posix_child operator()(const std::vector<std::string> args, 
               bp::posix_context ctx, 
               bp::stream_behavior bstdin = bp::close_stream(), 
               bp::stream_behavior bstdout = bp::close_stream(), 
               bp::stream_behavior bstderr = bp::close_stream(), 
               bool usein = false) 
        const 
    { 
        if (bstdin.get_type() != bp::stream_behavior::close) 
            ctx.input_behavior.insert(bp::behavior_map::value_type(STDIN_FILENO, bstdin)); 

        if (bstdout.get_type() != bp::stream_behavior::close) 
            ctx.output_behavior.insert(bp::behavior_map::value_type(STDOUT_FILENO, bstdout)); 

        if (bstderr.get_type() != bp::stream_behavior::close) 
            ctx.output_behavior.insert(bp::behavior_map::value_type(STDERR_FILENO, bstderr)); 

        if (ctx.environment.empty()) 
            ctx.environment = bp::self::get_environment(); 

        return bp::posix_launch(get_helpers_path(), args, ctx); 
    } 
コード例 #6
0
static std::string get_argument(const std::string &word) 
{ 
    std::vector<std::string> args; 
    args.push_back("helpers"); 
    args.push_back("echo-quoted"); 
    args.push_back(word); 

    bp::context ctx; 
    ctx.stdout_behavior = bp::capture_stream(); 
    ctx.environment = bp::self::get_environment(); 

    bp::child c = bp::launch(get_helpers_path(), args, ctx); 
    bp::pistream &is = c.get_stdout(); 

    std::string result; 
    portable_getline(is, result); 

    const bp::status s = c.wait(); 
    BOOST_REQUIRE(s.exited()); 
    BOOST_CHECK_EQUAL(s.exit_status(), EXIT_SUCCESS); 

    return result; 
}