| | |
getting command into Unix Shell
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 16
Reputation:
Solved Threads: 0
Hi guys. I'm doing a programming, whereby I have to display a prompt of my own on the linux terminal. Example commandprompt>.
The program will then wait for user's input, example "ls -ali | more" or "ls -ali" and etc.
I will be using the following system call in my program namely, fork(), execlp(), wait().
I'm having problem now waiting the wait and execlp. I've no idea how to use the function wait, since i have no idea how i could get the status of my child process.
About using execlp, how do i make it robust? as in the user could be keying any amount of command. They could be piping a few things. like maybe... "ls -ali | more | ... | ..." or it could be simply be one command.
my codes:
The program will then wait for user's input, example "ls -ali | more" or "ls -ali" and etc.
I will be using the following system call in my program namely, fork(), execlp(), wait().
I'm having problem now waiting the wait and execlp. I've no idea how to use the function wait, since i have no idea how i could get the status of my child process.
About using execlp, how do i make it robust? as in the user could be keying any amount of command. They could be piping a few things. like maybe... "ls -ali | more | ... | ..." or it could be simply be one command.
my codes:
C++ Syntax (Toggle Plain Text)
int main() { char cmd[100]; int num=1; int counter=1; int status; pid_t pid; do { cout<<"UOWUnix>"; cin.getline(cmd,100); //strcmp will return o if the word quit is found in the system. counter = strcmp(cmd, "QUIT"); //when the counter is 0, quits the system. if(counter==0) { cout<<"Good bye"<<endl; }//end if //execute all the command here. else { pid=fork(); //tells the parent to wait here. How to get the status of the child!?!? if(pid>0) { //wait((int *) 0) cout<<"in parent!!! child id is "<<pid<<endl; } //This is the child. start to do the work here. For now can only do one command, ls only. else if(pid==0) { execlp(cmd, cmd,(char *)0); exit(0); } } }//end do while (counter !=0); }//end main
Last edited by Ancient Dragon; Oct 18th, 2008 at 12:33 pm. Reason: add code tags
![]() |
Similar Threads
- Implementing a unix shell running commands (Java)
- Sleep Command in UNIX Shell Scripting (Shell Scripting)
- UNIX shell programming. Times function isn't working right (C++)
- Making a UNIX Shell, so inexperienced at it (C++)
- [Bash] problem with script in sed command (Shell Scripting)
- i want help about the Simulate a Linux/UNIX shell, called MASH in the C (C)
Other Threads in the C++ Forum
- Previous Thread: Airline Reservation Portal
- Next Thread: Error using recursion
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





