sylzys
sylzys

Reputation: 167

Error while using symfony process / exec / shell_exec to launch gcloud compute ssh

I need to execute a gcloud coumpute ssh --command via php (I'll check on security later).

Whether I use exec, shell_exec or Symfony Process, the command crashes:

Example with Symfony process (same goes with exec or shell_exec), simple lscommand used for testing:

$process = new Process("/path/to/google-cloud-sdk/bin/gcloud compute ssh my-instance --command='ls' ");
$process->run();
if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}
echo $process->getOutput();

if (!$process->isSuccessful()) {

}

I am getting the following error :

gcloud crashed (AttributeError): 'NoneType' object has no attribute 'split'

Please note that the same command, copied-pasted directly in CLI, works perfectly.

Any hint please ?

Upvotes: 1

Views: 307

Answers (1)

Alioua
Alioua

Reputation: 1776

Here is the explanation to what happening, $_ENV does not actually set an environment variable, i.e. the variable will not propagate to any child processes you launch (except forked script processes, in which case it's just a variable in the script's memory) This explanaed Here.

Upvotes: 0

Related Questions