Handle input from file or stdin.