C input loop for shell

Posted by AustinM on Stack Overflow See other posts from Stack Overflow or by AustinM
Published on 2011-01-08T00:30:06Z Indexed on 2011/01/08 0:54 UTC
Read the original article Hit count: 157

Filed under:
|
|
|

So I'm working on creating a very simple C program that just preforms shell commands. This is what I have so far:

#include <stdio.h>
int main()
{
char input[30];
fputs("$ ", stdout);
fflush(stdout);
fgets(input, sizeof input, stdin);
system(input);
}

It works, but only for one command. For example if I compile and type ./cmd I get the $ prompt. If I type ls I get what I'm supposed to get. But then it exits and goes back to the regular system shell. How can I make it so after the user types a command it goes back to the "$" input.

© Stack Overflow or respective owner

Related posts about c

    Related posts about shell