1

Hello I have the following PHP function:

public function index()
{        
  $return_var = exec('/home/iosef/createinstanceinfolder.sh');
  print_r($return_var);
}

Which is calling the following bash script in ubuntu 20.04:

#!/bin/bash

$my_array=(foo bar)
$my_array[0]=foo

How can I return this array to PHP?

1 Answer 1

1

Exec takes 2 more parameters.

try:

  $return_var = exec('/home/iosef/createinstanceinfolder.sh', $output, $retval);

Then print_r($output);

Also $output basically returns everything displayed by your script so in your script echo as a json or print_r your array in the end

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.