Reputation: 7128
I need to run 2 command after each other with exec
but it won't run.
$command1 = 'cd '.$destination.''; //open destination folder (e.g. public_html)
$command2 = 'git clone '.$repos->repository.''; //make clone
$sshConnection1 = exec($command1); // run first command(open folder)
$sshConnection = exec($command2); //run second command (make clone)
Before I create this question I read some of suggested topics like this one. to add "&"
etc. but no luck.
Please tell me what should I do in order to run both commands successfully.
Upvotes: 1
Views: 222
Reputation: 2524
You can simply put both commands into one exec()
call by combining them with &&
:
exec("cd $destination && git clone {$repos->repository}");
Upvotes: 1
Reputation: 23
It looks like PHP's exec
forks at some point, so that cd
isn't going to affect the parent process.
php > echo getcwd();
/home/nchambers
php > exec("cd ..");
php > echo getcwd();
/home/nchambers
php > echo exec("pwd");
/home/nchambers
php > exec("cd ..");
php > echo exec("pwd");
/home/nchambers
php >
Also, git clone
can take a destination directory to write to. I can't say why your commands are failing without more information, but just some initial problems with what you're trying to run.
Upvotes: 1