Hi All,
I have read that the system call "execlp" will take the first arguement as the file name(or path), second arguement as the command and all others are arguements to the command terminated by NULL.
i have written below program.
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define PATH "/home/FILE/test"
int main(void) {
int fd,st;
fd = fork();
if(fd == 0) {
printf("In child\n");
if (execlp(PATH,"test","hello","how","are","you",(char *)0)){
printf("Exec succ\n");
}else {
printf("Exec fail\n");
}
} else {
printf("In parent\n");
wait(&st);
}
}
the program is working correctly if i use the PATH macro as it gives the full path of the file image.
but if i replace PATH with "test"(image name) i am getting the out put as
In parent
In child
test: extra argument `how'
i dont understand the problem.
please some body point out where it is going wrong.
for your reference test.c
int main(int argc , char **argv)
{
int i= 0;
for(;i<argc-1;){
printf(" %s \n", argv[++i]);
}
printf("this is a test\n");
return 0;
}
Thanks in Advance,
Gaiety.