I am making a shell interpreter which works only with keyboard input, but I have to make it work with a text files.
int main(int argc, char *argv[], char *envp[]) {
string comando;
mi_argv[0] = NULL;
int pid_aux;
el_prompt = "$> ";
if(argv[1] != NULL)
{
ifstream input(argv[1]);
if (!input)
{
cerr << "No se reconoce el archivo " << argv[1] << endl;
exit(EXIT_FAILURE);
}
}
while(!cin.eof())
{
cout << el_prompt;
getline(cin, comando);
...
}
}
The point is to make this work with a file like argument ./shell file.txt
. I tried to redirect the file to cin
, but I don't know how to do it.