Boost logo

Boost :

From: (noreply_at_[hidden])
Date: 2007-03-09 15:56:52

Support Requests item #1677601, was opened at 2007-03-09 14:56
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Apoxy (apoxy)
Assigned to: Nobody/Anonymous (nobody)
Summary: program_options strips off escaped quotes in some situations

Initial Comment:
boost::program_options strips off escaped quotes from command line strings like -a "\"quoted value\"". A command line string like -a "\"quoted value\" unquoted_value" does not have its escaped quotes striped out.

I am using program_options in Windows to parse the command line of my application. One of the requirements is that I be able to pass in the command line of a different application such as the following:
myapp -c "\"c:\App versions\App v1\App.exe\" -a \"A Value\" -b Another_Value"

In this case, program_options will correctly parse out the value of the parameter c to be:
"c:\App versions\App v1\App.exe" -a "A Value" -b Another_Value

However, if I pass in the following:
myapp -c "\"c:\App versions\App v1\App.exe\""

program_options parses c as:
c:\App versions\App v1\App.exe

Note that the escaped quotes were stripped off instead of preserved like you would expect. This is a problem because my application immediately turns around and calls ::CreateProcess using the value of the c parameter. ::CreateProcess' documented behavior is that it executes the first match it can find of c:\App.exe, c:\App versions\App.exe, and c:\App versions\App v1\App.exe. The only way you can stop this behavior is by enclosing the file path in quotes.

The code I'm using to get the options is pasted below. Please email me with any questions. Thanks!


pair<string, bool> CCmdLineParser::GetParam(const string& sParamName)
        Run(); // Make sure we're parsed
        if (!Impl_.bOptionsDescribed && !Impl_.bPositionalOptionsDescribed)
                return GetUnregisteredParam_(sParamName);
        return Impl_.RegisteredOptions.count(sParamName)
                ? make_pair(Impl_.RegisteredOptions[sParamName].as<string>(), true) : make_pair("", false);

void CCmdLineParser::Run(void)
        if (Impl_.bInitialized)
        Impl_.bInitialized = true;

        // Create parser
        command_line_parser Parser(split_winmain(AfxGetApp()->m_lpCmdLine));
        bool bUnregistered = !Impl_.bOptionsDescribed && !Impl_.bPositionalOptionsDescribed;

        // Setup parser
        Parser.options(Impl_.OptionsDesc); // Always required (even if empty) because command_line_parser::run() asserts it
        if (Impl_.bPositionalOptionsDescribed)
        if (bUnregistered)

        // Parse
        parsed_options ParsedOptions =;

        // Retrieve
        // We can't call store on something with unregistered options. It throws an exception even if you specifically
        // call allow_unregistered(). This is a known bug. It is fixed in the boost CVS tree, but not released yet.
        // What all of this basically means if that we can't mix registered and unregistered options (yet).
        if (bUnregistered)
                Impl_.UnregisteredOptions = collect_unrecognized(ParsedOptions.options, include_positional);
        else {
                store(ParsedOptions, Impl_.RegisteredOptions);
                // notify() is required for automatic value storage and default values


You can respond by visiting:

Take Surveys. Earn Cash. Influence the Future of IT
Join's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
Boost-bugs mailing list

Boost list run by bdawes at, gregod at, cpdaniel at, john at