Boost logo

Boost :

Subject: [boost] [process] working directory issue
From: Bertolino, Keith D. (KBertolino_at_[hidden])
Date: 2012-05-15 11:08:29


I'm attempting to use boost::process to launch a command line tool
called "catdoc.exe." Catdoc takes one argument (the path to a word
document). Catdoc will then extract the text from the doc file and
output it via standard error to the command line which I've redirected
into a string below. So far everything works with the below code except
instead of getting the text out of "a.doc" I get an error saying "catdoc
cannot find codepage 1251" these codepages are saved in a directory
called "charsets" which is saved in the same place catdoc.exe. The
problem, I believe, is that the working directory is not set as Catdoc
works fine (and finds the codepages) when I execute it manually from the
command line, outside of my C++ code. My two questions are as follows:

 

1. Is there a way to set the working directory (and if so, will
this fix my problem)?

2. Is there a way to set a time-out on the underlying process (ie.
kill the process if it becomes unresponsive)?

 

Thanks in advance for your help!

 

My Code:

 

using namespace boost;

 

process::child start_child()

{

    string exec = "catdoc.exe";

    std::vector<std::string> args;

    args.push_back("C:\\a.doc");

 

    process::context ctx;

    ctx.stderr_behavior = process::capture_stream();

 

    return process::launch(exec, args, ctx);

}

 

string ExtractText()

{

    string rawtext = "";

 

    process::child c = start_child();

    process::pistream &is = c.get_stderr();

    std::string line;

    while (std::getline(is, line))

    rawtext += line;

                

    return rawtext;

}

 

v/r

-Keith

 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk