char * cmd="ls -l";
This should be:
char cmd[] = "ls -l";
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
>Are there any good solution
Yes, Dave's solution is a good one. Your code will fail because string literals can't be modified, and strtok modifies the string you pass to it. Changing cmd to an array fixes the problem.
Just in case you didn't catch it, remove the parts in red and add the parts in blue.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
><-- this is not executed why ??
$ man execvp
That should tell you pretty quickly what happens when execvp is called.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401