laravelコントローラの関数で実行されるbashスクリプトがあり、スクリプトの実行中にその中からエコーを出力したい。私はこの方法で試してみましたが、うまくいきませんでした。bashスクリプトを実行中にLaravel 5.3でリアルタイムログを表示する
これは私がアヤックス
$.ajax({
data: parameters,
url: '/executeBash',
type: 'get',
beforeSend: function(){
console.log("executing...");
},
success: function(response){
console.log("success: %O", response);
},
error: function(response){
console.log("error: %O", response);
}
});
でこれはAjaxの機能
Route::get('/executeBash', '[email protected]_bash');
によって呼び出さweb.php Laravelルートファイルで私のルート文であることを行うコントローラ
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use File;
use Process;
use ProcessFailedException;
class DeployController extends Controller
{
//
public function execute_bash(command)
{
flush();
$fp = popen(command, "r");
while(!feof($fp))
{
// send the current file part to the browser
print fread($fp, 1024);
// flush the content to the browser
flush();
}
fclose($fp);
}
です
execute_bash関数のコマンドパラメータは、内部でいくつかのものを実行する.shスクリプトへのパスです。それは、エコーで出力を印刷します。それは
どのように私は私が欲しいWathのを達成することができますを終了した後
さて、.SHスクリプトは、右実行されているが、すべての出力(エコー)を示していますか?ありがとう!
もう少し詳しく説明できますか?たとえば、コマンドサンプルと成功コールバックの出力を追加できますか? – Hackerman
@Hackerman私は投稿を編集しました! – Quetool
私はそれを手に入れました。あなたは、リアルタイムのシナリオのようにあなたのスクリプトの出力を表示したい...今すぐ出力データは、スクリプトの実行が終了したら表示されますか? – Hackerman