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
48
votes
2 answers

Search and replace in VIM results in trailing characters

This is what I am attempting to do: %s/Article/

Article

/gi Unfortunately, every time i execute this command through my vim editor, it says: Trailing characters To mitigate the above, I executed the following: %s/\s*\r*$// And it executes…
Parijat Kalia
  • 4,929
  • 10
  • 50
  • 77
48
votes
2 answers

Using Boolean Flags in Python Click Library (command line arguments)

I'm trying to make a verbose flag for my Python program. Currently, I'm doing this: import click #global variable verboseFlag = False #parse arguments @click.command() @click.option('--verbose', '-v', is_flag=True, help="Print more output.") def…
Hackerman
  • 1,289
  • 1
  • 14
  • 29
48
votes
5 answers

Make a script which accept command-line arguments

What is the correct syntax for running a Node.js script with command-line arguments on Linux or Mac? To run the script with no arguments, I would simply use the command node stuff.js, but in this case, I'd like to run a script called stuff.js with…
Anderson Green
  • 30,230
  • 67
  • 195
  • 328
48
votes
3 answers

Should command line options in POSIX-style operating systems be underscore style?

Should the name of command line options for a program in a POSIX-style operating system be underscore-style, like --cure_world_hunger or maybe some other style? --cureworldhunger --cure-world-hunger --cureWorldHunger What's most common? What's…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
47
votes
9 answers

getopt.h: Compiling Linux C-Code in Windows

I am trying to get a set of nine *.c files (and nine related *.h files) to compile under Windows. The code was originally designed in Linux to take command line arguments using the standard GNU-Linux/C library "getopt.h". And that library does not…
john_science
  • 6,325
  • 6
  • 43
  • 60
46
votes
10 answers

Default sub-command, or handling no sub-command with argparse

How can I have a default sub-command, or handle the case where no sub-command is given using argparse? import argparse a = argparse.ArgumentParser() b = a.add_subparsers() b.add_parser('hi') a.parse_args() Here I'd like a command to be selected,…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
46
votes
3 answers

Accessing command line arguments in Objective-C

Is there any complete documentation (the interface is present in crt_externs.h) about this functions : _NSGetArgc and _NSGetArgv I can't get any documentation on the apple website about this functions.
iPadDevloperJr
  • 992
  • 3
  • 20
  • 34
46
votes
4 answers

How do you run a .exe with parameters using vba's shell()?

I have a target file path that is structured like example below. C:\Program Files\Test\foobar.exe /G What I need to do is be able to execute this file using VBA's shell() command. How do I have to format the file path to tell Shell() that there is…
Austin A
  • 2,990
  • 6
  • 27
  • 42
45
votes
9 answers

Check if Flag Was Provided in Go

With the flag package, is there a good way to distinguish if a string flag was passed? For example, when the flag is not passed, I want to set it to a dynamic default value. However, I want to set it to empty if the flag was provided but with a…
Kyle Brandt
  • 26,938
  • 37
  • 124
  • 165
45
votes
12 answers

When running a python script in IDLE, is there a way to pass in command line arguments (args)?

I'm testing some python code that parses command line input. Is there a way to pass this input in through IDLE? Currently I'm saving in the IDLE editor and running from a command prompt. I'm running Windows.
Ben Gartner
  • 14,413
  • 10
  • 36
  • 34
44
votes
6 answers

Batch-Script - Iterate through arguments

I have a batch-script with multiple arguments. I am reading the total count of them and then run a for loop like this: @echo off setlocal enabledelayedexpansion set argCount=0 for %%x in (%*) do set /A argCount+=1 echo Number of processed…
Toby
  • 3,815
  • 14
  • 51
  • 67
43
votes
3 answers

-static option for gcc?

I'm wondering what the -static option on gcc does. I need this option when compiling a certain application, however when I do I get the following error: gcc -static -O3 -o prog prog.c /usr/bin/ld: cannot find -lc collect2: ld returned 1 exit…
sj755
  • 3,944
  • 14
  • 59
  • 79
43
votes
6 answers

How do I access program arguments in Swift?

C and derivatives have argc and argv (and envp) parameters to their entry point functions, but Swift doesn't have one proper: top-level code is just code and it doesn't have parameters. How can one access the equivalent of argc and argv in a Swift…
zneak
  • 134,922
  • 42
  • 253
  • 328
42
votes
4 answers

Passing on command line arguments to runnable JAR

I built a runnable JAR from an Eclipse project that processes a given XML file and extracts the plain text. However, this version requires that the file be hard-coded in the code. Is there a way to do something like this java -jar wiki2txt…
Jason
  • 11,263
  • 21
  • 87
  • 181
42
votes
3 answers

Precedence order among properties file, YAML file, and Command Line arguments in SpringBoot

I have been using application.properties files since long in my Spring application. But recently I came across application.yaml files. What is the precedence order among all three and advantage (if there is one) of using individual. I know this…