I wrote a program that simulate the bash command in Linux, in C.
It works perfectly with inputs from the keyboard, meaning:
application > file: redirect stdout of app to file(write output to file)application < file: redirect stdin of app from file (read input from file)application >> file: redirect stdout of app to file (append output to file)app1 | app2: redirect stdout of app1 to stdin of app2app &: means that app should be executed in the background
All these work, when I enter the command from the keyboard, as mentioned above.
In order to complete my assignment, I need to add one more element, which is
redirection from a file. Meaning, if my program is called bashSimulator, then
if I do this:
bashSimulator < fileWithCommands
then my program needs to get all the commands from the fileWithCommands and execute them.
I have no idea how to do the redirection from a file.
app < inputfilefrom yourbashSimulatorand notbashSimulator < inputfile?inputfileand execute them withbashSimulator. I really do need to do :bashSimulator < inputfile. I need to read all the commands ininputfile, each command is separated from the other with\n... I thought about using theargvandargcofmainbut that didn't work .bashSimulatordoesn't do the redirection in the command you state; the shell that runs it does.app < inputfilemeans redirect stdin of app from file (read input from file). This also meansbashSimulatorwill receive the commands via stdin. In other words: Ifbashsimulatorwill always read the commands fromSTDINeverything should be fine