|
Boost : |
From: SourceForge.net (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:
https://sourceforge.net/tracker/?func=detail&atid=207586&aid=1677601&group_id=7586
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)
return;
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)
Parser.positional(Impl_.PositionalOptionsDesc);
if (bUnregistered)
Parser.allow_unregistered();
// Parse
parsed_options ParsedOptions = Parser.run();
// 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
notify(Impl_.RegisteredOptions);
}
}
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=207586&aid=1677601&group_id=7586
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-bugs mailing list
Boost-bugs_at_[hidden]
https://lists.sourceforge.net/lists/listinfo/boost-bugs
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk