[英]php ssh2_exec not executing java command
下面的代碼無法使用ssh2_exec獲取Java版本,我也嘗試了絕對路徑/ usr / bin / java,相同的代碼正在使用php --version,請問該問題的可能原因是什么?
已為/ usr / bin / java完成chmod 777
$connection = ssh2_connect('xx.xx.xx.xx', 22);
ssh2_auth_password($connection, $username, $password);
$stream = ssh2_exec($connection, 'java -version;');
stream_set_blocking($stream, true);
$tempVar = stream_get_contents($stream);
echo $tempVar; // nothing printed here
一個問題可能是您正在執行的命令中的分號。
$stdout_stream = ssh2_exec($connection, "java -version");
$err_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDERR);
$dio_stream = ssh2_fetch_stream($stdout_stream, SSH2_STREAM_STDDIO);
stream_set_blocking($err_stream, true);
stream_set_blocking($dio_stream, true);
$result_err = stream_get_contents($err_stream));
$result_dio = stream_get_contents($dio_stream));
檢查stderr流以查看是否返回錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.