- 論壇徽章:
- 0
|
本帖最后由 ljpdxj 于 2012-03-01 16:02 編輯
使用該函數(shù),為何它不能正確識別選項少了參數(shù)
比如
./Test --module --compress-method
其中--module是一定需要參數(shù)的
這里故意不給--module指定參數(shù),為何它會把--compress-method認為是它的參數(shù)。。。。
而不是返回程式想要的冒號: ? (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. |
|