Questions tagged [getopt-long]

Getopt::Long is a command line switch parsing library for Perl. For C-programming: The getopt and getopt_long functions automate some of the chores involved in parsing typical unix command line options.

The Getopt::Long Perl module is a parser for the POSIX command line switch syntax with GNU extensions. Both the traditional -s single character switches and the longer --longer switches are supported.

For C-programming: The getopt and getopt_long functions automate some of the chores involved in parsing typical unix command line options. For details, please see here.

190 questions
1
vote
4 answers

Can Getopt::Long accommodate variable option names?

I am writing a script that can do something like: script-name --resource1=xxx --resource2=xxx But this can go up to 50+. Is there a way to make GetOpt accept dynamic option names?
gdanko
  • 1,922
  • 4
  • 20
  • 31
1
vote
1 answer

Parsing command line mutual exclusion flags with their specific options in perl with Getopt::Long

I have several mutually exclusive flags witch have their own options. Lets say, if I invoke the "stop_service" flag, I want a "name" option; but if I invoke the "send_report" flag I want a "email" option. For parsing that I use "Getopt::Long". This…
framontb
  • 1,817
  • 1
  • 15
  • 33
1
vote
4 answers

Can I call Getopts multiple times in perl?

I am a noob to perl, so please try to be patient with this question of mine. It seems that if I make multiple calls to perl Getopts::Long::GetOpts method, the second call is completely ignored. Is this normal??(Why) What are the alternatives to…
Neeraj
  • 8,408
  • 8
  • 41
  • 69
1
vote
1 answer

Perl: Take arguments from both command line and [piped STDIN|file], using Getopt::Long

Hi I wanted to implement both command line argument1, and either piped STDIN (through lone single dash '-') or a filename as argument2, using Getop::Long in Perl. In perldoc it is merely mentioned a little bit "A lone dash on the command line will…
Yiran Guo
  • 9
  • 2
1
vote
1 answer

getopt_long not printing error message

I am using getopt and getopt_long to parse the arguments of a c++ program. When the arguments are given correctly, I dont have a problem. Also, when wrong short arguments are given, the error message is printed correctly. But when a wrong long…
R71
  • 4,283
  • 7
  • 32
  • 60
1
vote
1 answer

Parsing options having a common flag in C

I have a C program where I accept multiple arguments. Here, I have a common flag d for both data-store and disk. Is there a way that I can check for the flags in-order and get the value of store before I check with case d. I've tried various ways…
nidHi
  • 833
  • 3
  • 10
  • 21
1
vote
3 answers

Using Getopt::Long to drive a system command on linux

I am trying to execute a php script with arguments, using the following perl driver: #!/opt/local/bin/perl use strict; use warnings; use Getopt::Long; use Cwd; my %args = (); GetOptions( \%args, "NUM_AGENTS|a=s", …
kamal
  • 9,637
  • 30
  • 101
  • 168
1
vote
2 answers

Print default argument when using getopt in C++

static struct option long_options[] = { {"r", required_argument, 0, 'r'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; int option_index = 0; char c; while((c = getopt_long(argc, argv, "r:h", long_options,…
anc
  • 191
  • 1
  • 19
1
vote
1 answer

Call GetOptions in perl script from Python subprocess

I have python application running on ubuntu server 16.04 with lines like this: var1 = "--var1 " + var1 var2 = "--var2 " + var2 proc = subprocess.Popen(["sudo", "perl", "/path/script.pl", str(var1), str(var2) ], stdout=subprocess.PIPE) Perl script…
Coykto
  • 1,014
  • 9
  • 12
1
vote
1 answer

segfault with getopt_long()

for a school project I have to use getopt_long() or getopt_long_only(). Here is my loop: while ((get_opt_err = getopt_long(argc, argv, "p:x:y:n:c:f:h", &help_opt, NULL)) != -1) I have a segfault reported in valgrind like…
Oscar
  • 1,071
  • 13
  • 26
1
vote
1 answer

How could one determine that required argument of option is missing?

I use getopt_long on GNU/Linux machine. Initialize options list as: static struct option long_options[] = { {"mode", required_argument, 0, 9}, {0, 0, 0, 0} }; Have following line of code c = getopt_long(argc, argv, "", long_options,…
Bulat M.
  • 680
  • 9
  • 25
1
vote
1 answer

Do C getopt and getopt_long only work for main arguments?

the question is pretty clear, I wonder because the man says The getopt() function parses the command-line arguments. And I am trying to use it with another function which has the same signature as the main and the argc and argv are obtained with…
1
vote
4 answers

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…
Lazer
  • 90,700
  • 113
  • 281
  • 364
1
vote
1 answer

C getopt_long two required arguments for an option

is it possible to tell getopt_long I need two arguments if an option is given? For example if -i is present it would require two arguments next and parsing would fails if they aren't present.
1
vote
4 answers

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,…
BrianH
  • 7,932
  • 10
  • 50
  • 71