脚本宝典收集整理的这篇文章主要介绍了php – 脚本在命令行后不会继续,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
试图直接通过putty调用命令行,它输出很多错误但是立即返回/完成.为什么不返回PHP呢?
码
$Cmd = new Command; if($err = $Cmd->exec('/VAR/bin/poppler-0.51.0/utils/pdfimages -list /var/test.pdf')){ echo "ERR: $err\n"; } echo "continue\n";
类
class Command { PRivate $descriptorsPEc; private $output = ''; private $process; private $pipes = []; public function __construct(){ $this->descriptorspec = [ 0 => ['pipe','r'],// stdin 1 => ['pipe','w'],// stdout 2 => ['pipe','w'] // stderr ]; } public function output(): string{ return $this->output; } public function close(){ foreach($this->pipes as $pipe){ if(is_resource($pipe)){ fclose($pipe); } } proc_close($this->process); } public function exec(string $Syntax){ $this->process = proc_open($Syntax,$this->descriptorspec,$this->pipes); fclose($this->pipes[0]); $this->output = stream_get_contents($this->pipes[1]); $stderr = stream_get_contents($this->pipes[2]); $this->close(); return $stderr; } }
# /var/bin/poppler-0.51.0/utils/pdfimages -list /var/test.pdf page num type width height color comp bpc enc interp object ID x-ppi y-ppi size ratio -------------------------------------------------------------------------------------------- 1 0 image 2154 303 rgb 3 8 jpeg yes [inline] 289 292 - - Syntax Error (50560): Illegal character '>' Syntax Error (50560): UnkNown operator '<10><07><82>;w<ad><a2><b4>2r<1f><10><07><8f>~j<c4>Hq<CF>Z<86>' Syntax Error (50568): UnkNown operator '<0f><b5>X<8f><ae><d0>:<d7>DU<91><cb>'v' Syntax Error (50568): Illegal character ')' ........ Syntax Error (66698): Illegal character <04> in hex string Syntax Error (66699): Illegal character <ff> in hex string Syntax Error (66699): Illegal character <c1> in hex string Syntax Error (66705): UnkNown operator '<9b>' Syntax Error (66714): Illegal character ')' Syntax Error (66714): UnkNown operator '<bc>q<ff>' Syntax Error (66720): UnkNown operator '<05>6<f8><c2><fa><d7><c3>?<f8>' Syntax Error (66741): UnkNown operator '<df><ec><99><e1>-' Syntax Error (66743): UnkNown operator ']' Syntax Error (66762): UnkNown operator '<cc>' Syntax Error: Unterminated string Syntax Error: End of file inside array Syntax Error: End of file inside array Syntax Error: Leftover args in content stream
但是,从PHP方面来看,使用try / catch块而不是if语句,你应该保留对脚本的控制.
$Cmd = new Command; try { $err = $Cmd->exec('/var/bin/poppler-0.51.0/utils/pdfimages - list/var/test.pdf')){ } catch (Exception $e) { var_LOG($e); } echo "continue\n";
以上是脚本宝典为你收集整理的php – 脚本在命令行后不会继续全部内容,希望文章能够帮你解决php – 脚本在命令行后不会继续所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。