简体   繁体   English

如何获取PHP ssh2_exec命令的退出状态?

[英]How to get exit status of PHP ssh2_exec command?

I want to get the exit status of ssh2_exec command.I tried following code but it it is giving me the output of jar file but i want only the status for success or failure.How can i get that, please help. 我想获取ssh2_exec命令的退出状态。我尝试了以下代码,但它给了我jar文件的输出,但是我只想要成功或失败的状态。我该如何获取,请帮忙。

$stream = ssh2_exec($connection, 'path of jar file');
stream_set_blocking($stream,true);
$output = ssh2_fetch_stream($stream,SSH2_STREAM_STDIO);
echo stream_get_contents($output);

You should use stderr instead: 您应该改用stderr:

$output = ssh2_fetch_stream($stream,SSH2_STREAM_STDERR);

If there are no errors, it's a success. 如果没有错误,那就成功了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM