I'm substituting a Perl sender script for your C++ program here, but this is the idea. You may need to use sysread, instead of the <> operator, there may be blocking problems in the pipes on win32 platforms, and error checking is needed. P.S. To control your C++ program, print to the STDIN filehandle.... i didn't include that feature here because I'm lazy and didn't want to add listener code into the sender script. But look at IPC3 buffer limit problem for a non-gui full control over a script.

sender_program script ( like your C++ program)

#!/usr/bin/perl use warnings; use strict; $| = 1; my $count = 0; while(1){ $count++; print "$count\n"; warn "\tuh oh warning $count\n"; sleep 1; }

and the Tk reader script

#!/usr/bin/perl use warnings; use strict; use IPC::Open3; use Tk; use Tk::ProgressBar; my $mw = new MainWindow; $mw->geometry("600x400"); my $tframe = $mw->Frame()->pack(); my $count = 0; my $l1 = $tframe->Label(-text => '%', -bg => 'black', -fg => 'green', )->pack(-side => 'left'); my $l2 = $tframe->Label( -text => $count, # -text option better here, than textvariable which # may cause unicode display problem #-textvariable => \$count, #may cause unicode display problem over a socket -bg => 'black', -fg => 'green', -width => 3, )->pack(-side => 'left'); my $p = $tframe->ProgressBar( -troughcolor => 'black', -fg => 'lightgreen', -blocks => 1, -width => 20, -length => 200, -from => 0, -to => 100, -variable => \$count, )->pack(-side =>'right'); my $tout = $mw->Scrolled( 'Text', -foreground => 'white', -background => 'black', -width => 80, -height => 20, )->pack; $tout->tagConfigure( 'red', -foreground => 'red' ); my $pid = open3( 0, \*OUT, \*ERR, "sender_program" ); #the 0 is for ignoring \*IN (STDIN) $mw->fileevent( \*OUT, 'readable', \&write_out ); $mw->fileevent( \*ERR, 'readable', \&write_err ); MainLoop; ############################################### sub write_out { $count = <OUT>; chomp $count; # eval $count; #prevents raw unicode, you may not need it # print "$count\n"; $l2->configure( '-text' => $count); # works better than textvaria +ble $tout->insert( "end", "$count\n" ); $tout->see("end"); } ############################################ sub write_err { my $str = <ERR>; $tout->insert( "end", "\t$str", 'red' ); $tout->see("end"); } __END__

I'm not really a human, but I play one on earth Remember How Lucky You Are

In reply to Re: Perl/Tk C++ Interaction by zentara
in thread Perl/Tk C++ Interaction by dmarg

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.