Reputation: 189
i have this code
switch(fork()){
case -1: perror("fork");
exit(1);
case 0:
if(chdir("cd /var/code/p1"))
system("make");
break;
default:
break;
}
in /var/code/p1 is a make file and a code file (if i tipe make in this directory its work) , this code is in /var/code/p2.
My problem is : this code is not compile the code from /var/code/p1, this are compile the code from /var/code/p2 , so what i do wrong?
Upvotes: 1
Views: 258
Reputation: 613451
chdir("cd /var/code/p1")
should be
chdir("/var/code/p1")
And the if test is incorrect since chdir returns 0 on success. You need
if (chdir("/var/code/p1") == 0)
system("make");
Upvotes: 3