Something weird is happening when I'm starting a Perl script under powershell and redirecting STDOUT to a logfile

PS D:\tmp> perl -E"$|=1;print $]" >.\tmp.log # writ +es log immediately PS D:\tmp> cat .\tmp.log 5.032001 PS D:\tmp> perl -E"$|=1;print $];sleep 100" >.\tmp.log # does +n't write log Terminating on signal SIGINT(2) PS D:\tmp> cat .\tmp.log # empt +y PS D:\tmp> exit d:\tmp>perl -E"$|=1;print $];sleep 100" >.\tmp.log # writ +es log immediately Terminating on signal SIGINT(2) d:\tmp> type .\tmp.log 5.032001

What am I missing? Is this a bug in Perl or Powershell?

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

update

Couldn't reproduce the even after finishing sleep part anymore

update

OK to make sure that it's not a side effect from -E I created a (very) short script.pl

PS D:\tmp> echo '$|=1;print $];sleep 10' > tst.pl PS D:\tmp> cat .\tst.pl $|=1;print $];sleep 10 PS D:\tmp> perl tst.pl # prints immediately 5.032001 PS D:\tmp> perl tst.pl >tmp.log Terminating on signal SIGINT(2) PS D:\tmp> cat .\tmp.log PS D:\tmp> PS D:\tmp> perl tst.pl >tmp.log # don't CTRL-c, just wait PS D:\tmp> cat .\tmp.log 5.032001

again,

  • if I run the script without redirection I see the output immediately
  • if I redirect, the log isn't written while sleeping
  • if I terminate with CTRL c the log isn't written either
  • only if I wait 10 sec I'll see the log written

    In reply to (WIN) Autoflush, Perl, Sleep and Powershell by LanX

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.