2017-08-28 20 views
0

ユーザが選択して送信するラジオボタンオプションでリモートゲートウェイベースを呼び出す単純な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. 

答えて

1

あなたは、物事のように作業するとき、あなたに結果を与える必要がありますフラグSSH2_STREAM_STDIOを使用しています期待される。問題がある場合は、フラグSSH2_STREAM_STDERRが必要だと思います。

ssh2_fetch_streamを参照してください:http://php.net/manual/en/function.ssh2-fetch-stream.php

そしてSSH2_STREAM_STDERR定義済み定数に:http://php.net/manual/en/ssh2.constants.php

+0

完璧な、また最後の事は出力SSH2_STREAM_STDIOとSSH2_STREAM_STDIOの両方への道がありますか? – kkmoslehpour

+0

一度に1つしか要求できません。出力されることがわかっても、 'SSH2_STREAM_STDIO'から何も返されなかった場合、' SSH2_STREAM_STDERR'をチェックすることができます。それ以外の場合は、毎回両方のチェックを省略することができます。 – neuromatter

関連する問題