My program should accept three kinds of input commands below:
./Myprogram input.txt
./Myprogram < input.txt
./Myprogram
I am thinking of using argcto check the number of arguments to resolve the first two situations (since redirection is not considered an argument). But then I got stuck in the latter case, which is just waiting for user input.
I am wondering if there is a way to find out if redirection is present in the shell command?
For a more complex scenario, such as a combination of forwarding and argv forms (see below). Is there a way to do this or is it just a bad design for accepting custom commands?
./Myprogram input1.txt input2.txt input3.txt
./Myprogram input1.txt < input2.txt input3.txt
./Myprogram
Any help would be greatly appreciated!
Zen
source
share