2017-04-09 11 views
0

私はフロントエンドにボタンを持っていますが、このボタンはバックエンドに話します。 バックエンドは、リモートスクリプト始めている:私は2つの問題、最初のものを持っているPHP:SSH接続とPythonスクリプトの実行

<?php 
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); 
$connection = ssh2_connect('192.168.56.180', 22); 
ssh2_auth_password($connection, 'root', 'password'); 
$stream = ssh2_exec($connection, 'python /WATSON/APP/test/testlistrbk.py'); 
stream_set_blocking($stream, true); 
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO); 
echo $stream_out_contente; 
fwrite($myfile, $stream_out); 
fclose($myfile); 
?> 

を、それがhere言ったようにPHPが終了するPythonスクリプトを待たなければならないが、それはしません。 )(fwriteのパラメータ2は、ライン41上/var/www/html/WEBAPP/wa_start.phpに与えられた文字列リソースであることを期待:

PHPの警告:

2つ目は、それは私に次のようになりますあなたのコード$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);

+0

'のvar_dump($のstream_out)のプット出力は;' fwriteのここで前 –

答えて

1

使用stream_get_contents(stream_out);

これはresourceない文字列出力を返します。このコードを試してください。

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); 

$connection = ssh2_connect('192.168.56.180', 22); 
ssh2_auth_password($connection, 'root', 'password'); 
$stream = ssh2_exec($connection, 'python /WATSON/APP/test/testlistrbk.py'); 

stream_set_blocking($stream, true); 

$outputStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO); 
$errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR); 

echo "Output: " . stream_get_contents($outputStream); 
echo "Error: " . stream_get_contents($errorStream); 

fwrite($myfile, $outputStream.$errorStream); 
fclose($myfile); 
+0

@MouIdriの$ stream_out'は '$ stream_out = ssh2_fetch_stream($ストリーム、SSH2_STREAM_STDIO)から受信されます'確認してください; ' –

+0

@Mouldriますあなたのコードの最後の3行を私のコードに置き換えるだけです。 –

+0

申し訳ありませんが、私は行方不明の$を見ませんでした。私はそれを変更し、私はもうエラーメッセージがありません。しかし、何もファイルに書き込まれていないので、動作は非常に奇妙です(私は0777をchmodedしたので、権利の問題ではありません)。 – MouIdri

関連する問題