in reply to Perl/Tk run program

Try using an entry widget like so:
use Tk; use warnings; use diagnostics; use strict; my $text; my $mw = MainWindow->new; $mw->title("PerlRun"); $mw->Entry(-width => 30, -textvariable, \$text)->pack(-anchor => 'nw', -side => 'top'); $mw->Button(-text => " Run ", -command => \&runprog ) ->pack(-side => 'left', -anchor => 'sw'); $mw->Button(-text => "Done", -command => sub { exit }) ->pack(-side => 'left', -anchor => 'sw'); sub runprog { system($text); } MainLoop;
If you wanted to use the Text widget, than your only problem was that you were trying to run the command on the ref to the $text widget instead of the variable in the runprog sub, so.. what you really wanted to do is this:
my $cmd = $text->get('0.1','end'); chomp $cmd; system($cmd);
Take a look at the Mastering Perl/Tk by Steve Liddie... great book :)
Cheers,
JamesNC

Replies are listed 'Best First'.
Re: Re: Perl/Tk run program
by st_possenti (Monk) on Jul 29, 2003 at 03:39 UTC
    That works great. Next, how do I get the process to run in the background and the perlrun to quit, without it stopping the program I just started. I am really new to perl and I do not know the commands. I have Learning Perl/Tk by Schwartz & Phoenix, O'reilly. Thank you for your help.
      Try using backticks and you can bg it like you would any unix process from the command line, I am on WinXP and would probably use Win32::Process... but you can just do something like:
      my $rv = `someprog &`; # try this instead of your system() call...
      Since I am not on a Unix box that is an untested line
      Tk's main loop keeps running until you exit... There is a better way to do non-blocking system calls however... you should do some reading of the perl/tk faq's or read about it in Mastering Perl/Tk which is an O'Reilly book ( ISBN 1-56592-716-8) I believe the Schwartz book you are referring to is "Learning Perl". The Perl/Tk book is all about the Perl/Tk implementation and assumes you already are familiar with Perl.
      JamesNC
        JamesNC you gave me the idea to try the & inside my system call. I came up with this.
        system("$text &"); exit;
        I put this im my sub, and it works great. I am going to expand this to hold a history and add error checking for commands inputed to make sure they work and let you know if you get a command not found. Thank you for the idea JamesNC. Thank you