ユーザが選択して送信するラジオボタンオプションでリモートゲートウェイベースを呼び出す単純なPHP関数があります(up.shまたはdown.sh)。私は正常にリモートゲートウェイからスクリプトを実行することができますが、何かが間違っているときはいつでも私のWebページはエラーを表示しません。ウェブページでエラーをエコーする方法はありますか?PHP bashスクリプトの実行後にリモートゲートウェイからエラーメッセージを出力する方法
testexe.php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
//create the ssh connection
if ($connection = @ssh2_connect($gateway, 22)) {
ssh2_auth_password($connection, $gwUser, $gwPwd);
if(isset($_POST['option']) && $_POST['option'] == 1) {
$stream = ssh2_exec($connection, "/home/user/aust/up.sh");
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
echo '<pre>' . stream_get_contents($stream_out) . '</pre>';
}
if(isset($_POST['option']) && $_POST['option'] == 2) {
$stream = ssh2_exec($connection, "/home/user/aust/down.sh");
stream_set_blocking($stream, true);
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
echo '<pre>' . stream_get_contents($stream_out) . '</pre>';
}
}
}
up.sh
#!/bin/bash
echo 'expect -f ./scripts/myExpectScript.exp' //I can see this on the webpage
expect -f ./scripts/myExpectScript.exp //this throws an error but i dont see the error on the page.
echo
エラー出力:
expect -f ./scripts/myExpectScript.exp
couldn't read file "./scripts/myExpectScript.exp": no such file or directory //I want to see this on the webpage.
完璧な、また最後の事は出力SSH2_STREAM_STDIOとSSH2_STREAM_STDIOの両方への道がありますか? – kkmoslehpour
一度に1つしか要求できません。出力されることがわかっても、 'SSH2_STREAM_STDIO'から何も返されなかった場合、' SSH2_STREAM_STDERR'をチェックすることができます。それ以外の場合は、毎回両方のチェックを省略することができます。 – neuromatter