3

I'm working on a project that needs to be run with either of the following commands:

./project.exe -Stack < [filename]

./project.exe -Queue < [filename]

I am wondering why there is a - in front of both Stack and Queue and why the filename is preceded by < and is in brackets.

The purpose of this format is to tell the program to either run using a stack class or run using a queue class. I will also need to extract the information from the text file mentioned in the command line.

I am familiar with general command line arguments and how to use them, but I have never seen this notation before and can't find any clear explanations.

2
  • 1
    this completely depends on what project.exe is. A program may choose any format for its comand line parameters it likes to choose. You could write a program that uses 42 as prefix for command line parameters Commented May 14, 2019 at 11:43
  • you have to ask the person who wrote project.exe Commented May 14, 2019 at 11:43

1 Answer 1

3

The dash for the options are simply a common convention. Usually with modern command-line programs one uses double-dash for so-called long options (like e.g. --stack) and single dash for short options (e.g. -s).

Many existing argument parsers, like the Linux getopt_long function, actually requires the single or double dashes for short and long options to be recognized as such.

The < is file redirection. It tells the shell to redirect the programs standard input from the file. Inside the program you can read from standard input (std::cin) and it will be automatically reading from the file. This redirection is handled entirely by the shell.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.