in reply to TK + Script
Update: Minor code fixes.#! /usr/bin/perl use strict; use warnings; use Tk; use Path::Tiny qw{ path }; my $safe_path = qr{^/safe/path}; sub select_and_run { my ($mw, $text) = @_; my $scriptfile = $mw->getOpenFile(-filetypes => [[Perl => '*.pl']] +); my $result; if ($scriptfile =~ $safe_path && -x $scriptfile) { my $output = qx{ $scriptfile }; my $exit_code = $?; path("$scriptfile.output")->spew($output); $result = "Exit code: $exit_code"; } else { $result = 'Cannot run'; } $text->insert(end => "$result\n"); } my $mw = 'MainWindow'->new(-title => 'Script Runner'); my $f = $mw->Frame->pack; my $text; my $button = $f->Button(-text => 'Run Script', -command => sub { select_and_run($mw, $text) } +)->pack; $text = $f->Text->pack; my $q = $f->Button(-text => 'Quit', -command => sub { Tk::exit })->pack; Tk::MainLoop();
|
|---|