Hello, i'm a newbie to Linus so there are many commands that keep me questioning.

My task is to write a program that will execute a list of commands from a text file. Everything go smooth except for the command execve, its prototype is something like int execve ( char *filename , char *argv[] , char *envp ) ; what i don't get it here is the third argument envp, i read online reference and some said it was predefined in unistd.h library, so i included the library but the command still didn't work, so i went on declaring globally: extern char ** environ ; and passed that to excecve's 3rd argument and now it works, but i don't know if i made any mistakes, and the program may went wrong in some cases, can anyone please explain more clearly to me what is this environment variable :-/

You could just use the execv() function instead, if all you're interested in is the default environment.

Yeah, thanx a lot for all of your helps, i used execvp and it runs ok, but some more problems, i don't know what directory the commands are run so i try "ls" and it said ls is not a command!

Does anybody know which directory the command is run when using exec?

exec is your basic function.

A 'v' means that the args are a vector, exactly like argv you get in main. execv( argv[0], argv ); is a good way of restarting yourself.

A 'l' means that the args are a list, ending with a (char*)NULL execl( "/bin/ls", "/bin/ls", "-1", (char*)NULL); A 'p' means that the PATH is searched for the command. Without a 'p', you should generally specify the absolute path the to executable (eg."/bin/ls") execlp("ls","ls","-l",(char*)NULL); A 'e' means you get to choose the environment to pass to the created process. Without it, it just inherits the current environment. Security concious apps prefer to pass a known environment for example.