getopt-long

How do I parse a string with GetOpt::Long::GetOptions?

I have a string with possible command line arguments (using an Read-Eval-Print-Loop program) and I want it to be parsed similar to the command line arguments when passed to Getopt::Long. To elaborate: I have a string $str = '--infile /tmp/infile_location --outfile /tmp/outfile' I want it to be parsed by GetOptions so that it is easi...

How can I override hard-coded configuration in my Perl program?

I have a Perl script that sets up variables near the top for directories and files that it will use. It also requires a few variables to be set as command-line arguments. Example: use Getopt::Long; my ($mount_point, $sub_dir, $database_name, $database_schema); # Populate variables from the command line: GetOptions( 'mount_point=s'...

Can Perl's Getopt::Long parse arguments I don't define ahead of time?

I know how to use Perl's Getopt::Long, but I'm not sure how I can configure it to accept any "--key=value" pair that hasn't been explicitly defined and stick it in a hash. In other words, I don't know ahead of time what options the user may want, so there's no way for me to define all of them, yet I want to be able to parse them all. Su...

Get optarg as a C++ string object

I am using getopt_long to process command line arguments in a C++ application. The examples all show something like printf("Username: %s\n", optarg) in the processing examples. This is great for showing an example, but I want to be able to actually store the values for use later. Much of the rest of the code uses string objects instead o...

getopt does not parse optional arguments to parameters

In C, getopt_long does not parse the optional arguments to command line parameters parameters. When I run the program, the optional argument is not recognized like the example run below. $ ./respond --praise John Kudos to John $ ./respond --blame John You suck ! $ ./respond --blame You suck ! Here is the test code. #include <stdio.h...

How can I make Perl's Getopt::Long not process a literal = in a parameter name?

I wrote a Perl program "transfer.pl" and the input parameter is the hash value (the key and the value are strings). The code segment is: my %transfers = (); if (!GetOptions("transfer=s" => \%transfers)) { Usage(); exit(1); } I used the windows system. On the command line, I typed: perl tranfer.pl --transfer "table = %s"="...

Is there anyway to persuade python's getopt to handle optional paramters to options?

According to the documentation on python's getopt (I think) the options fields should behave as the getopt() function. However I can't seem to enable optional parameters to my code: #!/usr/bin/python import sys,getopt if __name__ == "__main__": try: opts, args = getopt.gnu_getopt(sys.argv[1:], "v::", ["verbose="]) excep...

getopt_long vs getopt_long_only

Hi guys, to do a proper Linux/unix styled application, what is the best choice (eg. afaik ls uses getopt_long but for example ffmpeg getopt_long_only). Which one do you recommend? Cheers, ...

Why does my Perl program print the help message when an arguments has 0 as a value?

If i do this: GetOptions( 'u=s' => \$in_username, 'r=i' => \$in_readonly, 'b=i' => \$in_backup ); exit usage() unless $in_username && $in_readonly && $in_backup; and call the program like this: ./app.pl -u david -r 12 -b 0 it always results in calling usage(), so obviously the 0 is not seen as an integer value...

How can I handle -r=<pattern> with Perl's Getopt::Long?

I am parsing command line options in Perl using Getopt::Long. I am forced to use prefix - (one dash) for short commands (-s) and -- (double dash) for long commands (e.g., --input=file). My problem is that there is one special option (-r=<pattern>) so it is long option for its requirement for argument, but it has to have one dash (-) pre...

Where does getopt_long store an unrecognized option?

When getopt or getopt_long encounters an illegal option, it stores the offending option character in optopt. When the illegal option is a long option, where can I find out what the option was? And does anything meaningful get stored in optopt then? I've set opterr = 0 to suppress the automatically printed error message. I want to create...

How can I allow undefined options when parsing args with Getopt

If I have a command line like: my_script.pl -foo -WHATEVER My script knows about --foo, and I want Getopt to set variable $opt_foo, but I don't know anything about -WHATEVER. How can I tell Getopt to parse out the options that I've told it about, and then get the rest of the arguments in a string variable or a list. An example: use...

How to use Getopt::Long method?

How can I use Getopt::Long method if the input command execution is like this: $ testcmd -option check ARG1 ARG2 ARG3 or $ testcmd ARG1 ARG2 ARG3 ...

Is it possible to move backwards through a getopt_long argument list?

I would like to delegate to one of several possible lists of arguments based on whether particular arguments are present, along the lines of: ./test --do-thing-1 --option-A=7 --common-option --option-B=2 # options C and D not valid ./test --do-thing-2 --option-C=9 --common-option --option-D=1 # options A and B not valid And the best w...

Ruby GetoptLong how do I parse comma separated arguments?

Hi How can i parse arguments separated by comma in ruby? For example: $> Main.rb --xmlid 1,2,3,4,5 I want to parse and store 1,2,3,4,5 in an array. How can I do that? Thanks. ...

How to verify which flags were read using Getopt::Long in Perl?

myscript.pl my $R; my $f1 = "f1.log"; my $f2 = "f2.log"; my $f3 = "f3.log"; sub checkflags { GetOptions('a=s' => \$f1, 'b=s' => \$f2, 'c=s' => \$f3, ); open $R, '>', $f1 or die "Cannot open file\n"; # Line a } All the flags are optional. If I call the script as perl myscript....

Perhaps a pointer problem. Linux program + libpcap + getopt_long() + C language.

Hello! I'm making a network sniffer for my college project using the libpcap library. Majority of the code works without any problem, however, I'm stuck with the following issue. I've added five command line options using getopt_long() function, but one option doesn't work as expected. The option is -d (--device_info) and is used to pri...