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.

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 }
Thanks for whatever clues/examples you can provide.

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.


In reply to How can I redirect Windows command line output into a PerlTk frame by jfrai

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.