how to pass mutiple command using shell_exec

shell_exec(): multiple commands

The shell_exec() function is an inbuilt function in PHP which is used to execute the commands via shell and return the complete output as a string. The shell_exec is an alias for the back tick operator, for those used to *nix. If the command fails return NULL and the values are not reliable for error checking.

Syntax:

string shell_exec( $command )

Arguments: This function accepts single str argument $command which is used to hold the command that will be executed.

Return Value: This function returns the executed command or NULL if an error occurred.

Execute Multiple command: for execution multiple command using shell_exec() method we separate command with "&&" just like we do in terminal/cmd.

Syntax: shell_exec("cmd1 && cmd2");

Ex.
                                          
1> $output
= shell_exec('whoami && dir'); 2> echo($output);
 


Output:
mypc hello.txt main filezila.exe
 

Comments