Questions tagged [command-line-arguments]

Programming command line utilities that take parameters.

This tag should have questions relating to programming command-line utilities that take arguments.

A command line argument is a parameter passed to a command line program. For instance git status is the Git command line program with the parameter status. Git then acts accordingly to that parameter.

Command line arguments are used in command line programs from the Command Prompt on Windows, a shell on Unix and the Terminal program on Mac OS. These are not visual GUI programs, they are text based.

Learn more: Wikipedia Article Command Line

5018 questions
2
votes
1 answer

How to run different 'modes' of a program based on command line parameters?

I'm looking into Openssl's source code to find out how the programmers made it possible to run different applications based on command line arguments. For instance: I can run openssl speed, which has its own options, I can run openssl s_server which…
Brian Brown
  • 3,873
  • 16
  • 48
  • 79
2
votes
4 answers

Issues with C++ command-line arguments on Windows

I'm somehow having issues parsing command-line arguments on Windows in C++. I tried using this int main(int argc, char **argv) { std::cout << "Command-line argument count: " << argc << " \n"; std::cout << "Arguments:\n"; for (int i = 0;…
codefox
  • 31
  • 4
2
votes
2 answers

Is there a pythonic way of assigning values to variables when passed in from the command line?

I have written to following code but it feels very clunky and I was wondering if there was a pythonic way of writing the following code: import argparse foo = 0 bar = 1 parser = argparse.ArgumentParser() parser.add_argument("-a", "--foo",…
sunny
  • 530
  • 1
  • 6
  • 12
2
votes
2 answers

How to efficiently read environment parameters from file, to be used with exec

I want to be able to save to file the argv and environ of a process, and than, at a later time, to be able to fork and exec using the parameters that are saved to file. The only design I could think of, is to write to file the list of parameters as…
yaloner
  • 715
  • 2
  • 6
  • 19
2
votes
2 answers

Number of arguments in bash script

I want to test the number of arguments passed to a Linux shell script. If the number of arguments is not 2 or 4, it should print something. Unfortunately it does not work. Can anyone explain what I am doing wrong? #!/bin/bash if [[ $# -ne 2 ]] || [[…
Andrew Nick
  • 23
  • 1
  • 3
2
votes
2 answers

Running a program where I pass the filename into Main

Well I assume this answer is out there but man is there a flood of people posting the code. I cannot find where it is actually implemented. I am using codeblocks and I am passing the filename into main. But when I click Run, there is no filename…
2
votes
1 answer

Access command line argument inside bash function?

I'm trying to access a command line argument within the function below but I can't get it to work. I believe it has something to do with the quotes but I can't figure it out. search_second_line() { awk 'FNR==2 {if (/$1)/) print FILENAME;…
chishaku
  • 4,577
  • 3
  • 25
  • 33
2
votes
1 answer

How to use command arguments in paintComponent method?

I am currently trying to create a Java GUI program that generates images based on the arguments given in the terminal. If I get the argument in the command line java Draw Image1 for example, I want to draw my image 1 and etc. for the others. How can…
Ampage Grietu
  • 89
  • 1
  • 2
  • 10
2
votes
1 answer

Run parameters in a Powershell script from a batch file

I'm trying to specify parameters in a powershell script, from a batch file. The script itself looks likes this: Param( [Parameter(Mandatory=$true,HelpMessage="Application switch")] [string[]]$Apps, [ValidateRange(3,9999)] …
Zyph
  • 23
  • 1
  • 4
2
votes
2 answers

argparse optional parameter within positional

With argparse I would like to be able to mix optional parameters with multiple positional parameters, e.g., like svn allows: svn ls first/path -r 1000 second/path At the moment, this is not officially supported by Python (c.f.…
2
votes
3 answers

Passing Guid to Command Line parser Library in C#

I am using the nuget package Command Line Parser for parsing command line arguments in C#. How do I pass a GUID from command line? ApplicationName.exe -g="3a0e5412-0971-4e0e-aebc-29dd09907b31" does not work. My CommandLineArgs class is…
Rockstart
  • 2,337
  • 5
  • 30
  • 59
2
votes
2 answers

ImageMagick Command-Line Option Order (and Categories of Command-Line Parameters)

My supervisor has asked me to convert the parts of our Perl scripts that use PerlMagick to instead pipe and use the command line version of ImageMagick (for various unrelated reasons). Using the our existing interface (crop, scale, save, etc) I'm…
2
votes
1 answer

How can I read the command line supplied to an offline clickonce application?

I have a simple application that opens a TCP connection and communicates via Telnet to another system. The application is to read a file that contains parameters and a simple scripting language to issue commands based on prompts from the…
Adam Wood
  • 289
  • 2
  • 4
  • 13
2
votes
1 answer

How to manage command line arguments in docker run command?

I want to run this command inside a container: java -jar bin/felix.jar > log.txt If I manually do: frog@gooseberry:~/path$ sudo docker run -it 5fe6598e0648 /bin/bash root@9beabfb5e852:/path# java -jar bin/felix.jar > log.txt [... program running…
Manuel Durando
  • 1,493
  • 3
  • 19
  • 30
2
votes
1 answer

Finding filenames with patterns using command line arguments in Linux

So in my Systems Programming class, we were asked a question on how to search for all file names that are seven letters long, start with 'F' and the fifth letter is 'o'. I'm confused as to how to properly do this. I assume it involves the use of…