- 论坛徽章:
- 0
|
本帖最后由 ljpdxj 于 2012-03-01 16:02 编辑
使用该函数,为何它不能正确识别选项少了参数
比如
./Test --module --compress-method
其中--module是一定需要参数的
这里故意不给--module指定参数,为何它会把--compress-method认为是它的参数。。。。
而不是返回程式想要的冒号: ? (optstring第一个字符指定为了冒号)
感谢感谢!!!!!!!!!!
man 3 getopt_long:
RETURN VALUE
If an option was successfully found, then getopt() returns the option character. If all command-line options have been parsed, then getopt() returns -1. If getopt() encounters an option character that was
not in optstring, then ’?’ is returned. If getopt() encounters an option with a missing argument, then the return value depends on the first character in optstring: if it is ’:’, then ’:’ is returned; oth-
erwise ’?’ is returned.
getopt_long() and getopt_long_only() also return the option character when a short option is recognized. For a long option, they return val if flag is NULL, and 0 otherwise. Error and -1 returns are the
same as for getopt(), plus ’?’ for an ambiguous match or an extraneous parameter. |
|