Turning on autoflush on the handle worked for me (IIRC, this may require a use IO::File; on old Perls, before 5.14). Also please note the advice in Calling External Commands More Safely!

use warnings; use strict; open(my $Progress, '|-', qw/ zenity --title Explore --progress --percentage 0 --text Test --auto-close --auto-kill /) or die $!; $Progress->autoflush; foreach my $Percent ( qw{10 20 30 40 50 60 70 80 90 100} ) { sleep 2; print "DBG> ", $Percent, "\n"; print $Progress "$Percent\n"; print $Progress "# Test $Percent\n"; } close($Progress) or die $! ? $! : $?;

Update: And here's a version that handles the user clicking the "Cancel" button, which apparently causes a SIGHUP.

{ my $run = 1; local $SIG{HUP} = sub { $run=0; }; open(my $Progress, '|-', qw/ zenity --title Explore --progress --percentage 0 --text Test --auto-close --auto-kill /) or die $!; $Progress->autoflush; print $Progress "# Test 0%\n"; foreach my $Percent ( qw{10 20 30 40 50 60 70 80 90 100} ) { sleep 1 if $run; unless ($run) { print "Canceled\n"; last } print "DBG> ", $Percent, "\n"; print $Progress "$Percent\n"; print $Progress "# Test $Percent%\n"; } close($Progress) or $run and die $! ? $! : $?; print "Done.\n"; }

Update 2: Minor edits to second example.


In reply to Re: Linux Perl with zenity progress bar (updated) by haukex
in thread Linux Perl with zenity progress bar by EigenFunctions

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.