I'd like my app to read from files specified by command-line argument or from standard in, so the user can use it myprogram.exe data.txt
or otherprogram.exe | myprogram.exe
. How can I do this in C#?
In Python, I'd write
import fileinput
for line in fileinput.input():
process(line)
This iterates over the lines of all files listed in sys.argv[1:], defaulting to sys.stdin if the list is empty. If a filename is '-', it is also replaced by sys.stdin.
Perl's <>
and Ruby's ARGF
are similarly useful .