<>PHP call shell command

<> preface

Because I want to use it php call python script , So I thought we could use it php call shell Method implementation of command .
php edition :php7.0

<> Three methods

<>1.system

system — Executing external procedures , And display the output

How to use functions
system ( string $command [, int &$return_var ] ) : string
example:
<?php $last_line = system('ls',$return_val); echo(“last line:”.$last_line);
echo(“return:”.$return_val);
explain : Yes shell command , And output its return result directly ;
The return result of the function is shell The last line of the command output ;
$return_val by shell The return result of the command .

<>2.exec

exec — Execute an external program
exec ( string $command [, array &$output [, int &$return_var ]] ) : string
example:
<?php exec('ls',$out); var_dump($out);
explain :exec The return result of the function is shell The last line of the command output ;
$output by shell Command output content ;
$return_val by shell The command returns the result ;

<>3.passthru

passthru — Execute the external program and display the original output
passthru ( string $command [, int &$return_var ] ) : void
example:
<?php passthru('ls',$res); echo($res);
explain : When executed Unix The command outputs binary data , And it needs to be sent directly to the browser , You need to use this function instead exec() or system() function . By setting
Content-type by image/gif, Then call pbmplus Program output gif file , You can start from PHP Script output image to browser directly

Technology
©2020 ioDraw All rights reserved
Unity Illumination overview Common logic questions and pen questions for programmers Why do you need computer major after graduation java What about training ? Where do programmers go when they are over 40 Why do enterprises and factories do energy management and control system JAVA How to output log gracefully in the background Django Of defer and only Detailed explanation of methods Huawei Mate40 Suffer from a mountain stronghold , Carrying snapdragon 865 as long as 898 element One MySQL I'll just hang you up , How dare you write on your resume “ master ”? Gstarcad 3D Operation skills of assembling parts in software