![]() |
| | #1 |
| Registered User Join Date: Apr 2002
Posts: 17
| simple shell (c), fgets problem Could you please look at my source at http://razza.org/source.html (its formatted, and color coded) I have two problems, they seem to be related 1 ![]() when I use fgets to grab from the command line, rather than gets, I seem unable to run programs like ping ipaddress (ping doesnt receive the ip) If I use gets ping will work. 2 ![]() However my shell should also run programs in the background (that is fork the process off, and return to the command prompt before the process has finished). To do this you would type say echo hello & (the '&' should always trail), this by the way actually works for echo but if you try ls / & ( then it complains) I presumed that their is something wrong with the parse function, so I substituted another users function in, the shell then worked correctly with fgets. Since I check for the & symbol in my parse function I was unable to check wether the background process bug is also fixed. Hopefully one of you guys can tell me whats up with my parse function Thanks razza Last edited by razza; 05-25-2002 at 11:28 PM. |
| razza is offline | |
| | #2 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,693
| > when I use fgets to grab from the command line, rather than gets You've got to strip off that newline before passing the parameters to your programs > if you try ls / & ( then it complains) Can you be more specific? > its formatted, and color coded Well it's colour coded, but I wouldn't say it was formatted Formatted is where all the statements at the same scope level actually line up |
| Salem is offline | |
| | #3 |
| Registered User Join Date: Apr 2002
Posts: 17
| well for ls for example: ls / (lists directory contents properly) ls / & ls: : No such file or directory /: |
| razza is offline | |
| | #4 |
| Registered User Join Date: Apr 2002
Posts: 17
| Code: int parse(char *buffer, char **v) {
int temp = 0;
while (*buffer != '\0') // if not the end of buffer yet.
{
while (*buffer == ' ' || *buffer == '\t' || *buffer == '\n')
*buffer++ = '\0'; // replace white spaces (includes tabs etc..)
*v++ = buffer; // save buffer place to v.
wouldn't the above code take care of the final new line character? |
| razza is offline | |
| | #5 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,693
| > wouldn't the above code take care of the final new line character? On the face of it, yes But that doens't mean it actually works Try printing each v[i] using this loop Code: for ( i = 0 ; v[i] != NULL ; i++ ) {
printf( "param %d is '%s'\n", i, v[i] );
}
> Once out of the while loop v is null terminated with *v = '\0' *v = NULL; would be better |
| Salem is offline | |
| | #6 |
| Registered User Join Date: Apr 2002
Posts: 17
| Thanks I didn't think of putting the value in ' ', which did help me spot something ![]() Managed to fix it, so it works now. |
| razza is offline | |
| | #7 |
| Comment your source code! Join Date: Apr 2002
Posts: 533
| try calling the other functions from main and adding return 0; to main ERR nm
__________________ Asking the right question is sometimes more important than knowing the answer. Please read the FAQ C Reference Card (A MUST!) Pointers and Memory The Essentials CString lib |
| Lynux-Penguin is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem using sscanf fgets and overflow checking | jou00jou | C Programming | 5 | 02-18-2008 06:42 AM |
| Help: A Simple Shell | roaming_builder | C Programming | 6 | 02-10-2008 10:12 PM |
| problem with A simple modeless messagebox | hanhao | C++ Programming | 8 | 07-05-2005 11:18 PM |
| problem with fgets | learninC | C Programming | 3 | 05-19-2005 08:10 AM |
| C / OpenGL help REALLY needed for simple but annoying problem! | Oz_joker | C Programming | 5 | 12-03-2003 05:47 PM |