LoginSignup
0
0

More than 5 years have passed since last update.

October CMS プラグイン実装テク:LinuxコマンドのSTDOUTをリアルタイムで取得する

Last updated at Posted at 2017-10-19

OctoberCMSのコマンドからLinuxコマンドを使っていると、処理時間が長いときなど、リアルタイムでLinuxコマンドの出力をコンソールに表示したいことがあります。

OctoberCMSプラグイン作成Tips:Linuxコマンドを実行する」で使っていた Process#getOutput メソッドだと、処理が終わった後にSTDOUTの出力を取得することになります。

そこで Process#run メソッドに関数を渡してやることで、(ほぼ)コマンド出力のたびに呼び出されたびに任意の処理をさせることができます。
下記の例だと、OctoberCMSのコマンド実装クラスでLinuxコマンドのSTDOUT出力をそのままコンソールに出力しています。

$process->run(function ($type, $buf) {
    $this->output->write($buf);
});

参考:Getting real-time Process Output

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0