Pages

Using execlp

In the post "using execl" we saw how to launch a new process replacing the current one using execl. But the limitaion of execl is that if we have to execute a shell command or any other script that is not in the current woring directory as the new process, then we have to pass the full path of the command or the script.

The workaround to passing the full path of the executable is to use the functon execlp.
The syntax of execlp is :



Arguments:



As the executable is searched for in the path specified by the variable PATH, if the path to the executable is added to PATH it will be executed by execlp,thus any custom command or script can also be launched.

For example, in the following program we are using execlp to execute the command echo, with out mentioning the path to echo, which is not possible using only execl.



Ouput :




No comments:

Post a Comment