Skip to content
Advertisement

How do I read the whole command line?

JavaScript

Command $ ls -l | ./main.out

The output will show

JavaScript

My question is, how do I make my program to read the command before that, ls -l

Advertisement

Answer

Command line parameters are passed as arguments when calling the program. And your program will read the entire command line arguments.

But What you are doing ($ ls -l | ./main.out) is piping standard output of the command ls -l into the standard input of the program ./main.out.

To read from stdin, do Something like:

JavaScript

See Reading piped input with C++ and http://www.site.uottawa.ca/~lucia/courses/2131-05/labs/Lab3/CommandLineArguments.html

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement