use Tk; use IPC::Open3; use IO::Handle; use Win32::Process::Kill; use threads; use threads::shared; use Thread::Queue; $q=Thread::Queue->new; $qe=Thread::Queue->new; unlink('out.txt'); my %font=(-font=>[-family=>'Courier New',-size=>10]); my %width=(-width=>120); $pid = open3( \*CHILD_IN, \*CHILD_OUT, \*CHILD_ERR, 'cmd.exe' ); print "pid = $pid\n"; sleep(1); threads->create(\&handle_child_out)->detach; threads->create(\&handle_child_err)->detach; print "threads created\n"; autoflush CHILD_OUT; autoflush CHILD_ERR; my %font=(-font=>[-family=>'Courier New',-size=>10]); my %width=(-width=>118); my $mw=new MainWindow; my $entry=$mw->Entry( %width, -relief=>'groove', -borderwidth=>5, -textvariable=>\$entry_text, %font )->pack; $entry->focus; $entry->bind('<Key-Return>',\&enter); my $text=$mw->Scrolled('Text', -insertontime=>0, -scrollbars=>'e', %font, %width, -height=>43 )->pack; my $geom=$mw->geometry; $geom='+5+5'; $mw->geometry($geom); $mw->after(500,\&handler); MainLoop; Kill($pid); sub enter { print CHILD_IN "$entry_text\n"; $entry_text=''; $entry->focus; } sub handler { while(($q->pending)||($qe->pending)) { my ($content,$contente); if($q->pending) { $content=$q->dequeue; $content=~s/\r//g; } if($qe->pending) { $contente=$qe->dequeue; $contente=~s/\r//g; } my ($x,$y)=$text->yview(); $text->insert('1.0',"$content$contente"); $text->yview(moveto=>$x); $entry->focus; } $mw->after(500,\&handler); } sub handle_child_out { sleep(1); do { sysread CHILD_OUT, $content, 4092; if($content ne '') { $q->enqueue($content); } } while(1); } sub handle_child_err { sleep(1); do { sysread CHILD_ERR, $content, 4092; if($content ne '') { $q->enqueue($content); } } while(1); }

In reply to Re^2: Windows cmd.exe output -> Tk text widget? by chessgui
in thread Windows cmd.exe output -> Tk text widget? by chessgui

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.