[英]PHP Net_SSH2 - exec() how to get the command return code
如何获取执行的命令的返回码:
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('www.domain.tld');
if (!$ssh->login('username', 'password')) {
exit('Login Failed');
}
echo $ssh->exec('cat /tmp/file_tmp');
//verify the return code
echo $ssh->exec('echo $?');
?>
echo $?
(Linux)和echo %errorlevel%
(Win)不起作用。
有任何想法吗??
$ssh->getExitStatus()
能做你想要的吗?
找到一个选项(解决方法)。 PHP ssh2_exec通道退出状态?
以下代码对我有用,符合我的目的:
$command .= ';echo "[return_code:$?]"';
$output = $ssh->exec($command);
preg_match( '/\[return_code:(.*?)\]/', $output, $match );
$return_code = $match[1];
echo "\r\n". $output;
echo "\r\n".$return_code;
感谢大家的投入。 欣赏它!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.