Reputation: 328
I am trying to run shell commands from PHP using
<?PHP
$output = shell_exec('gcloud --version'." 2>&1");
echo "$output";
?>
The output which I get is
sh: 1: gcloud: not found
When I try to do
shell_exec('ls -l')
It works as expected. I have related posts on StackOverflow to use Rest API instead on this. But I have created a big script with gcloud commands. I am running my shell scripts in Terminal in mac. Can anyone help me understand the issue. May be required to install sdk, tried that still got same issue.
Upvotes: 1
Views: 291
Reputation: 724
You need to read up on Relative Path
vs Absolute Path
of a file/dir.
When you code shell_exec('gcloud --version'...
, you are using relative path
.
One way to resolve your issue is to specify the absolute path
to gcloud
command which can be determined from bash
command line by typing:
which gcloud
and you might get a result like
/usr/lib/google-cloud-sdk/bin/gcloud
Then, change your PHP code to shell_exec('/usr/lib/google-cloud-sdk/bin/gcloud --version'...
Upvotes: 0