c - getopt does not parse optional arguments to parameters -
In C, getopt_long does not parse the optional argument in the command line parameter parameter.
When I run the program, alternative logic is not recognized as an example run below.
$ ./pm --praise John kudos to John $ ./respond --blame John suck you! $ / Tomorrow - Blame you suck!
Here is the test code.
#include & lt; Stdio.h & gt; # Include & lt; Getopt.h & gt; Int main (int argc, char ** argv) {int getopt_ret, option_index; Static structure options long_options [] = {{"compliment", required_community, 0, 'p'}, {"fault", optional_gram, 0, 'b'}, {0, 0}}; While (1) {getopt_ret = getopt_long (argc, argv, "p: b ::", tall_paction, and option_index); If break (getopt_ret == -1); Switch (getopt_ret) {case: break; Case 'P': printf ("value% s \ n", optarg); break; Case 'B': printf ("You suck"); If (optarg) printf (",% s! \ N", optarg); Other printf ("! \ N", optgz); break; Case '?': Printf ("Unknown option \ n"); break; }} Return 0; } Although not specified in the glibc documentation or getopt man page, long Alternative argument for style requires command line parameters 'equal sign' (=). The space that separates the optional argument from the parameter does not work.
An example is run with the test code:
$ ./respond --praise John Kudos John $ / Laudable - John / John - John Crowd John $ / - Let's suck you! $ ./respond --blame = John, you suck, John!
Comments
Post a Comment