0

here is what I want to do: The user needs to enter a command at the prompt and the program will evaluate the command to know what to do. If the command is not found then the shell will return the error "Command not found!". If the user enters the command EXIT then the program should exit. For simplicity and to avoid a problem with users pressing enter with nothing typed we will assume that users will always enter something. No empty strings will be used. I should to this with a loop here is what I want to do:

Example:

shell.exe

Shell>test

Command not found!

Shell>test2

Command not found!

Shell>exit

>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char command[20];

    while (command != "exit") {

        //check with an if statement for valid commands
        printf("Enter a command:\n");
        gets(command);
    }

    if (command == "exit") {
        //program should exit
    }

    return 0;
}
drescherjm
  • 9,653
  • 5
  • 43
  • 62

1 Answers1

-1

Use either popen() or system(). Popen gives a handler for i/o while system gives a shit, but you can still redirect to a pipe ( "<" and ">" ) on the command line and read and write i/o your way from there.

  • I'am not really sure but maybe that works if you do write(0,&datatowrite,quantofbytestowrite) as i/o writing when with system(). – jm marti Oct 08 '16 at 15:00