[prev] 33 [next]

IO Redirection

  • If program runs from terminal: stdin, stdout, stderr connected to terminal.
  • Unix shells allow you to re-direct stdin, stdout and stderr.
  • Run a.out with stdin coming from file data.txt

    ./a.out < data.txt
    

  • Run a.out with stdout going to (overwriting) file output.txt

    ./a.out > output.txt
    

  • Run a.out with stdout appended to file output.txt

    ./a.out >> output.txt
    

  • Run a.out with stderr going to file errors.txt

    ./a.out 2> errors.txt
    

  • Run a.out with stdout AND stderr going to file allOut.txt

    ./a.out &> allOut.txt