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
0
votes
0 answers

c- parsing command line options with multiple arguments with getopt_long

I am new to c programming using command line arguments so despite finding few simmilar posts I am still stuck on this problem. I need to pass a command line option that have more than 1 argument, for example ./testProgram --command arg1 arg2…
Saik
  • 993
  • 1
  • 16
  • 40
0
votes
1 answer

Parsing option arguments in terminal using getopt_long in C

I'm just having a problem when parsing my option arguments through terminal. When executing my c file, I can only have one option which is the file name. I can enter the file name with two options (a short option and a long option):…
jamal
  • 543
  • 1
  • 4
  • 5
0
votes
1 answer

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…
James
  • 24,676
  • 13
  • 84
  • 130
0
votes
2 answers

detecting no argument with getopt_long

How do I detect the user passed no arguments to a program with getopt_long? I could detect the user calling the program with no arguments by checking argc, but what about the user calling my program with just a dash? $ my_prog - Do I need to…
0
votes
2 answers

GetOptions Optional 2nd value to an argument

I would like an option where the first value is mandatory, and the 2nd value is optional. For example, ./foo --arg mandatory optional If I use =s{2} the user is forced to enter the second option. I don't want to allow n-number of values...I want…
Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
0
votes
1 answer

Using getopt in C for command line arguments

I am working on trying to take in command line arguments. If I want to have multiple optional command line arguments how would I go about doing that? For example you can run the program in the following ways: (a is required every instance but -b -c…
sudobangbang
  • 1,406
  • 10
  • 32
  • 55
0
votes
2 answers

Getopt::Long passing several arguments to a subroutine

How to pass several arguments from command line to a function in Getopt::Long? My problem is as follows. I define options in the following way: ... my $result = GetOptions('ham=s{2}' => \&hamming_distance); ... sub hamming_distance { my @values…
Pida
  • 13
  • 3
0
votes
1 answer

getopt_long treat option name as argument

I was using getopt_long read command line options. code: #include #include #include int main(int argc, char *argv[]) { int ch; struct option longopts[] = { {"password", required_argument, NULL, 'p'}, …
leeyiw
  • 414
  • 2
  • 6
  • 14
0
votes
2 answers

getopt_long: only modify flag if user supplied command-line option

OK, so basically I would like getopt_long to only modify a flag variable if the user supplied a command-line option to do so. Otherwise, I want the flag left alone. I've found a solution for this, but it's not very beautiful. In particular, if…
Douglas B. Staple
  • 10,510
  • 8
  • 31
  • 58
0
votes
1 answer

using getopt_long, how to store two values in optarg?

If I define static struct option long_option[]={ {"add", 1, 0, 'a'} } can I store two values in the optarg? This is the code what I want to use: ./a.out --add Tommy 123-123-123 and I would like to store two values, Tommy and 123-123-123 by using…
0
votes
1 answer

How to restrict "--" using getopt in linux c?

I have to restrict when the user gives "--" as an option. For example: ./test -- should thrown an error. For the sake of parsing I am using getopt How to achieve this using getopt?
samairtimer
  • 826
  • 2
  • 12
  • 28
0
votes
3 answers

parse all arguments and store to hash

How can i parse all the arbitrary arguments to a hash without specifying the argument names inside my perl script. Running command with below argument should give hash like below. -arg1=first --arg2=second -arg3 -arg4=2.0013 -arg5=100 { …
Pungs
  • 2,432
  • 1
  • 16
  • 14
0
votes
1 answer

perl pass through tab via Getopt::Long

I have a simple script where I want the user to be able to specify the separator: #!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $sep = "&"; GetOptions('sep:s' => \$sep); my @list = ('a','b','c'); print join($sep,@list); print…
719016
  • 9,922
  • 20
  • 85
  • 158
0
votes
1 answer

getopt argument depends on another

is there a builtin way to make an argument depend on another when using getopt? For example, I have my switch case setup and everything works fine, but I need my -m argument (the length of the markov chain) before I read a text file (-i). In other…
scx
  • 3,221
  • 1
  • 19
  • 37
0
votes
1 answer

getopt: not recognizing valid command line arguments

I'm C++ programming in a linux environment and I'm trying to parse command line arguments using getopt. I want to require an input -s OR -q (longforms --stack and --queue respectively), not both, as well as an input -o with a required argument: int…
Jack Knudson
  • 51
  • 1
  • 2
  • 10