Pass multiple commands to shell_exec

Seems like an obvious question, but I can’t seem to get shell exec to execute multiple commands. I try a simple program like

$string =


And I receive results from only the first “whoami”.

How would I receive results from both whoami’s (both commands)?

… send two shell_exec’s?

Of course that could be done but that would include a lot of repetition. The real list of commands I want to use is over 1 thousand lines, at one command per line.

this is what the [FPHP]explode[/FPHP] and [FPHP]foreach[/FPHP] commands were made for…

$commands = explode("\n",$commands);
foreach($commands AS $command) {
  $stuff = shell_exec($command);
  //Do stuff with the $stuff

That said, if you’ve got 1000 lines of commands to run, stick them in an actual shell script, and call that instead.

That’s a nice solution, thanks.

My commands are currently in a shell script that is very hard to maintain. I am trying to convert everything to php as much as possible because its much easier for me to manipulate.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.