int main(void)
{
execl("echo", "test");
return 0;
}
I want to execute command echo test with execl
Why ? Because i can't use system()
i have some reasons
What is wrong ?
The execl
function does not look up commands on your PATH like a shell would, so you need to provide the full path to echo
(or else provide a relative path from your current working directory, I think). Also, the first arg in the args list should be the filename of the executable, and the last arg should be NULL
so that execl can figure out how many args you are trying to pass.
This works for me:
#include <unistd.h>
int main(void)
{
execl("/bin/echo", "/bin/echo", "test", NULL);
return 0;
}
You can run which echo
to find out where echo
is located on your system; it might be different from mine and you would have to edit the code.