Redirecting from files using the <operator in C

I wrote a program that mimics a command bashin Linux, in C. It works great with keyboard inputs , which means:

  • application > file: redirect application stdout to file (write output to file)
  • application < file: redirect application stdin from file (read input from file)
  • application >> file: redirect application stdout to file (add output to file)
  • app1 | app2: redirect stdout from app1 to application stdin2
  • app &: means the application should run in the background

All this works when I enter a command from the keyboard, as mentioned above.

To complete my task, I need to add another element, which is a redirect from the file. Meaning, if my program is called bashSimulator, then if I do this:

bashSimulator < fileWithCommands

fileWithCommands .

, .

+3
1

stdin, . isatty(3), , .

+5

All Articles