You can use getenv to get the contents of a certain environment value (such as "PATH"). Use man getenv for details.
The reason it seems like it's running another instance of your current shell is because you've forked your shell into a new process. So the program's doing exactly what you've asked it to do. If execvp fails, it simply returns -1. (If it succeeds, it never returns!) Then your child process keeps running until it finds a reason to exit, and then the parent's wait( ) call comes through, and the parent continues.
If you want to handle this, simply include something to handle it after your execvp call. If the call fails, you can write, "Bad command or filename\n", or whatever you want, and then exit() that process. Then the parent's wait() returns, and the parent continues running.
Reputation Points: 1135
Solved Threads: 173
Super Senior Demiposter
Offline 2,479 posts
since Jun 2005