cURL live output CLI

徘徊边缘 提交于 2019-12-23 21:29:02

问题


I try to have a "live output" of a web page in a shell script ; to explain, a little example :

With this "localhost/index.php" like this:

<?php
header('Content-type: text/html; charset=utf-8');
echo 'Start<br />'.PHP_EOL;
for( $i = 0 ; $i < 10 ; $i++ )
    {
        echo '.';
        flush();ob_flush();
        sleep(1);
    }
echo PHP_EOL.'<br />End';
?>

I want to write a shell script which permit to have the "dots" on the screen that appears each second.

If I try this :

#!/bin/bash
curl 'localhost/index.php'

It shows the output only after each breaklines... Not after each update (or "echo" in PHP script) If a pipe this, all output will be show at the end :/

Is there a way to have the real time output, like in a browser ?


回答1:


Perhaps curl's -N / --no-buffer option will help you?



来源:https://stackoverflow.com/questions/30070818/curl-live-output-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!