Hello! I\'m trying to build a command line interpreter simulator using C program
ID: 3795701 • Letter: H
Question
Hello!
I'm trying to build a command line interpreter simulator using C programming language, working in the linux environment. I don't want to get in to designing the whole thing, I just want a little help with a particular problem. This particular problem is how do I write a line or lines in C that will run a command as if I had typed it in the terminal? More specifically, the command I'm trying to run is "help." The command that shows all available commands.
So for example, I want to simulate the "ls" command, the command that lists the content of the current directory. I would go into my editor and type this:
#include <stdio.h>
#include <stdlib.h>
int main()
{
system("ls");
return 0;
}
Now if I go into the terminal, compile that program and run it, it'll display the content of the current directory as would simply typing in "ls" in the terminal. The problem is, I can't manage to do the same for the "help" command. After researching a bit, I've found that the sh shell is looking in /bin and /usr/bin to execute "help." However, that command is in neither directory and will ultimately let me know that the command is "not found." If it's not in the earlier mentioned directories, then where could it be? Is it even possible to run "help" within a C program?
Sorry if it's a little long, I just wanted to be as clear as I can be. Any help would be greatly appreciated!
Explanation / Answer
you need to us ,
system ("/bin/ls");
Below is the update
*******************************************************
Also , you can use the below program to list the directories,
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.