#!/usr/bin/perl use warnings; use strict; use Gtk2; ## todo: change mnemonic into an accelerator (^D) ## todo: do another one for quitting (^Q) ## bug (fixed by forking): halts on infinite loops :^P my ($window, $vbox, $ptext, $but, $label); my $font = 'Monospace 10'; my $perl = '/usr/bin/perl'; sub do_run { my $pid; my $buf = $ptext->get_buffer; local $SIG{'CHLD'} = 'IGNORE'; warn "fork: $!" and return unless defined ($pid = fork); if ($pid) { ## parent $ptext->grab_focus; return; } ## child $pid = open my $fd, '|-', $perl, '-t' or die "fork: $!"; print "\n$perl PID: $pid\n"; ## for easy killing print $fd $buf->get_text ($buf->get_bounds, 1); close $fd; exit; } Gtk2->init; $window = Gtk2::Window->new ('toplevel'); $vbox = Gtk2::VBox->new (0, 0); $ptext = Gtk2::TextView->new; $but = Gtk2::Button->new; $label = Gtk2::Label->new_with_mnemonic ('_Run!'); $but->signal_connect (clicked => \&do_run); $but->add ($label); $but->set_size_request (50, 30); $ptext->set_size_request (50, 20); $ptext->set_border_width (4); $ptext->modify_font (Gtk2::Pango::FontDescription->from_string ($font) +); $ptext->get_buffer->set_text (<<_DEF_TEXT_); use warnings; use strict; use Data::Dumper; \$ENV{'PATH'} = \$ENV{'CDPATH'} = '/usr/bin:/bin'; _DEF_TEXT_ $vbox->add ($ptext); $vbox->pack_end ($but, 0, 0, 0); $window->signal_connect (destroy => sub { Gtk2->main_quit; }); $window->set_default_size (700, 400); $window->add ($vbox); $window->show_all; Gtk2->main;

In reply to pexec.pl: snippet runner by Hue-Bond

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.