| | |
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 arrays based beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete deploy desktop developer directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





