jfrai has asked for the wisdom of the Perl Monks concerning the following question:
I have several Perl scripts I use to perform installations of various tools. To avoid command line mistakes, I've been reading through PerlTk documentation and have fumbled my way to a point where I have a decent GUI with nice little checkboxes for tool selection and some path selections. Lo and behold, I even have the background Perl scripts working with the GUI to properly install the programs.
However, all the output from the Perl scripts go to the cmd window that the PerlTk main window was initially launched from. I would like to have the command windows (for the child Perl scripts) opened in a new frame, with the resulting commands and output directed into that window. I've not been able to find a decent example of this.
I attempted something like the following, obviously simplified for doing a simple "dir," but I couldn't seem to get any output. Eventually, I would like to compile this so that I don't have to rely on TCL and Perl dependencies, so getting the output into a frame is important for the GUI.
Thanks for whatever clues/examples you can provide.use strict; use Tk; use Tk::Button; use Tk::Checkbutton; use Tk::LabEntry; use Tk::Label; my $cmdLineText; my $mw=MainWindow->new(-title=>'Foo Installer'); my $row = 0; my $w_install = $mw-> Button ( -overrelief=>'raised', -relief=>'raised +', -text=>'Install', -command=>\&installItems) -> grid(-column=>0, -r +ow=>++$row, -columnspan=>3, -sticky=>'nsew'); my $w_cmdWindow = $mw->Label (-height=>7, -foreground=>'white', -backg +round=>'black', -text => $cmdLineText)->grid(-column=>0, -row=>++$row +, -columnspan=>3, -rowspan=>10, -sticky=>'nsew'); MainLoop; sub installItems { open (FILE, "dir 2>&1 |"); #appears to do nothing $cmdLineText = ""; while (<FILE>) { chomp; $cmdLineText .= $_; } close(FILE); #$cmdLineText = `dir`; #appears to do nothing #system "dir"; #outputs to original screen }
Update1: The first answer that mentioned using "cmd.exe /c ..." works well for Windows commands, like "dir," but unfortunately doesn't handle output from Perl scripts in the same way. Thank you, though. That's another tool for my toolbag.
Update2: I attempted to use the "tie" procedure but couldn't seem to get that to work properly. I'll look into IPC::Run.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How can I redirect Windows command line output into a PerlTk frame
by frieduck (Hermit) on Mar 05, 2009 at 01:28 UTC | |
|
Re: How can I redirect Windows command line output into a PerlTk frame
by KSURi (Monk) on Mar 05, 2009 at 08:55 UTC | |
by BrowserUk (Patriarch) on Mar 05, 2009 at 16:14 UTC | |
|
Re: How can I redirect Windows command line output into a PerlTk frame
by zentara (Cardinal) on Mar 05, 2009 at 12:18 UTC | |
|
Re: How can I redirect Windows command line output into a PerlTk frame
by BrowserUk (Patriarch) on Mar 05, 2009 at 16:15 UTC |