Connecting Tech Pros Worldwide Help | Site Map

Getting console output

Newbie
 
Join Date: Feb 2009
Posts: 4
#1: Feb 13 '09
Hi again!

I need some help \ pointers on how to get the output generated in a console after you run a system command into a text widget (Perl Tk). I feel rather confident that I could get the data put into the widget if I could actually GET the data to begin with, but I can't seem to get this done :(

e.g. system "someAppThatGeneratesConsoleOutput.exe" -> get the output that is generated from this..

Can't really explain any better, hope you understand :) Seen this done before (cross linux\windows with a simple method..) But I don't have that code anymore and I cant seem to remember how.
nithinpes's Avatar
Expert
 
Join Date: Dec 2007
Posts: 400
#2: Feb 15 '09

re: Getting console output


You may use reverse quotes to run the system command and capture the results into a variable and later insert it to Tk Textbox:
Expand|Select|Wrap|Line Numbers
  1. my  $TextBox= $fr->Scrolled( 'Text', '-scrollbars' => 'e', '-background' => 'yellow',       
  2.   )->pack( -fill => 'both', -expand => 1, -side => 'bottom' );
  3.  
  4. my @res=`dir /w`; ##Pass your comand within reverse quotes
  5.  
  6. $TextBox->insert('end',"@res");
  7.  
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Feb 15 '09

re: Getting console output


You can also use what I think is a more readable quoting operator that does the same thing as the backtiks:

my @res= qx{dir /w};
Newbie
 
Join Date: Feb 2009
Posts: 4
#4: Feb 15 '09

re: Getting console output


Ah Wonderful! :D Thanks a lot =)
Reply