3

Hi I'm trying to pass a Shell Command to a variable in php and I'm doing

$var=system('ls');

and it is executed but the output it is echo as default not in the variable i use to

$var=exe('ls');

or

$var=exec('ls');

but print_r just print the last file on the list, why it is happen ? and how i get to do so ?

1 Answer 1

4

Use shell_exec:

$var=shell_exec('ls');

or exec:

exec('ls', $output, $return_var);

# print array
foreach($output as $content){
  echo $content . "\n";
}
print "return_var:" . $return_var . "\n";
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.