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

How to enforce required command-line options with NDesk.Options?

I was just writing a console utility and decided to use NDesk.Options for command-line parsing. My question is, How do I enforce required command-line options? I see in the docs that: options with a required value (append '=' to the option name)…
BigJoe714
  • 6,732
  • 7
  • 46
  • 50
34
votes
6 answers

Split a string containing command-line parameters into a String[] in Java

Similar to this thread for C#, I need to split a string containing the command line arguments to my program so I can allow users to easily run multiple commands. For example, I might have the following string: -p /path -d "here's my description"…
Kaleb Pederson
  • 45,767
  • 19
  • 102
  • 147
34
votes
3 answers

Use Robocopy to copy only changed files?

I'm trying to find an easy way of deploying only changed files to the webserver for deployment purpose. In times past I've used MSBuild, which could be told to only copy files that were newer than the ones on the target, but I'm in a hurry and…
Cyberherbalist
  • 12,061
  • 17
  • 83
  • 121
34
votes
3 answers

How to silently delete files with a bat file

del /s .jpg deletes all .jpgs .. but the problem is: it shows, in cmd when executed => C:\blabla..\this.jpg is deleted.. I want to turn this off. Such that user will not know what is happening (i.e, what files are being deleted).
Deb
  • 5,163
  • 7
  • 30
  • 45
32
votes
3 answers

What is the lldb equivalent of gdb's --args?

I'm used to running gdb like so: $ gdb --args exe --lots --of --flags -a -b -c d e ... (gdb) r Is there an equivalent for lldb?
Claudiu
  • 224,032
  • 165
  • 485
  • 680
32
votes
7 answers

Setting PHP enviromental variable while running command line script

I need to run a PHP script from command line and I need to set some environmental variables. Unfortunately, following does not work: php -dAPPLICATION_ENV=staging script.php What I'd like to accomplish is having APPLICATION_ENV variable set.
Wiktor
  • 2,909
  • 4
  • 17
  • 23
32
votes
2 answers

Specifying include directories on the cmake command line

Is it possible to specify an include directory when running cmake. For example cmake . -INCLUDE=/foo/bar The header files are in a separate directory from the sources that I would like to compile, and I would like to remedy this without tinkering…
Olumide
  • 5,397
  • 10
  • 55
  • 104
32
votes
1 answer

Command Line Parser with mutually exclusive required parameters

I started to use the CommandLine Parser Library for a tool that will have both a GUI and a command line execution. Launching the GUI is done via a command line option. I would therefore like to have required options in case the program is executing…
Julien Jacobs
  • 2,561
  • 1
  • 24
  • 34
31
votes
5 answers

How can I process command line arguments in Python?

What would be an easy expression to process command line arguments if I'm expecting anything like 001 or 999 (let's limit expectations to 001...999 range for this time), and few other arguments passed, and would like to ignore any unexpected? I…
user63503
  • 6,243
  • 14
  • 41
  • 44
30
votes
2 answers

Are the strings in argv modifiable?

I just wrote a small program that reads command line arguments in C, nothing too difficult. I was also modifying them, for example changing the first character of the parameter to uppercase. I know that you shouldn't modify string literals as it…
ash.KETCHUP
  • 323
  • 4
  • 8
30
votes
1 answer

Flag command line parsing in golang

I'm not sure I understand the reasoning behind this example (taken from here), nor what it is trying to communicate about the Go language: package main import ( "flag" "fmt" ) func main() { f := flag.NewFlagSet("flag",…
lollercoaster
  • 15,969
  • 35
  • 115
  • 173
29
votes
4 answers

Haskell: Parsing command line arguments

This more of a style question, rather than a how to. So I've got a program that needs two command line arguments: a string and an integer. I implemented it this way: main = do args@(~( aString : aInteger : [] ) ) <- getArgs let parsed@( ~[(n,_)]…
rampion
  • 87,131
  • 49
  • 199
  • 315
29
votes
2 answers

Passing an optimization flag to a Go compiler?

To compile a Go program you type go build myprogram.go, can you pass an optimization flags along or the code is always compiled in the same way? I am talking about speed optimizations, code size optimizations or other optimizations. I know if you…
exebook
  • 32,014
  • 33
  • 141
  • 226
29
votes
1 answer

Windows cmd pass output of one command as parameter to another

In linux it is possible t do this: git diff $(git status -s -b | sed -n '2p' | cut -d' ' -f2-) or a simpler case ls $(pwd) The question is how can I achieve the same in windows? (not using a batch file, a one liner in command prompt). Not all…
Arijoon
  • 2,184
  • 3
  • 24
  • 32
29
votes
2 answers

Python sys.argv and argparse

I have been looking for ways to add argument values to a script when I run it from the command line. The two packages I have found that seem to do this are sys.argv and argparse. I'd also like to be able to add some sort of help function if…
Stephen Berndt
  • 433
  • 1
  • 5
  • 10