in reply to (WIN) Autoflush, Perl, Sleep and Powershell

Hi LanX,

I am using perl 5.28, but I get the log getting written after sleep completes, I tried different timegap

PS C:\Users\VinothG> perl -E"$|=1;print $];sleep 10" >.\tmp.log PS C:\Users\VinothG> cat .\tmp.log 5.028001 PS C:\Users\VinothG> perl -E"$|=1;print $];sleep 20" >.\tmp.log PS C:\Users\VinothG> cat .\tmp.log 5.028001 PS C:\Users\VinothG> perl -E"$|=1;print $];sleep 30" >.\tmp.log PS C:\Users\VinothG> cat .\tmp.log 5.028001 PS C:\Users\VinothG> perl -E"$|=1;print $];sleep 40" >.\tmp.log PS C:\Users\VinothG> cat .\tmp.log 5.028001 PS C:\Users\VinothG> perl -E"$|=1;print $];sleep 100" >.\tmp.log PS C:\Users\VinothG> cat .\tmp.log 5.028001

My PowerShell Version

PS C:\Users\VinothG> Get-Host | Select-Object Version Version ------- 5.1.18362.1474

All is well. I learn by answering your questions...

Replies are listed 'Best First'.
Re^2: (WIN) Autoflush, Perl, Sleep and Powershell
by LanX (Saint) on May 14, 2021 at 16:35 UTC
    > but I get the log getting written after sleep completes

    yes sorry, I couldn't reproduce that part anymore.

    But $|=1 aka autoflush should guaranty that it's written immediately, please try CTRL-c while sleeping and see if there is any output.

    My interest is in reading the output of long running scripts in realtime.

    FWIW I tried both quotes " and ' for the -E part.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      «My interest is in reading the output of long running scripts in realtime.»

      What about Get-Content with the flags -Tail and -Wait?

      «The Crux of the Biscuit is the Apostrophe»

        That's what I already do on the reading side.

        But my problem here is on the writing side.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery