Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

capturing standard output 2

Status
Not open for further replies.

mastermagrath

Technical User
May 21, 2004
28
0
0
US
Hi,

I've been using PERL quite succesfully for post processing logs etc. However i've thought of a useful idea that i'm not sure how to go about doing. This time rather than making a tool to post process static text files i was thinking about how i could do the following (in windows):

run a perl script in a console window.
the script actually runs/calls a dos FTP script i have.
the output normally seen from the FTP script in the console window is captured and processed by the script as it arrives and produces its own customised output for the user to see.

I have no idea how to begin this because i don't really know what i need and thus what to look for! Thanks in advance.
 
Look up Net::FTP, better yet Net::SCP on and forget about the console, you can output to browser if you do it as a cgi-app

--Paul

cigless ...
 
You can use qx// or backticks (``) to execute an external program and grab the output, e.g.:
Code:
my $output = `perl otherscript.pl`;
# or . . .
my $output = qx/perl otherscript.pl/;
 
Hey, thanks for the fast reply, tek-tips just gets better.
I must admit i feel a bit lost!! It'll take me a while to look into this and understand what's on offer in the website you suggested.
Just for the record, when you say to forget about the console, do you mean i can script up PERL tools and have them run on a browser? This sounds interesting as one of the other things that would be useful is if i could make my tools easily available via a web browser rather than having to download the tool to a new machine, then hope perl is installed on the machine and then run it.
I think i should really read a PERL book so i know what PERL has to offer completely..........
 
Hi Ishnid,

This looks more like what i was thinking of. However it looks like this construct captures all of the output into a variable for the duration of the external program. What worries me is i don't need to 'keep' all of the output i.e. what would be ideal would be to capture the output character by character and discard them once processed. Otherwise this variable could waste memory?

Cheers
 
use the open routine to capture the output.

EX:

open(CMD, "perl otherscript.pl|") || die "ERROR\n";
while (<CMD>){
close(CMD);

The "|" will attach the output from the otherscript.pl to be tied to the file handle CMD. You can loop through the output like reading a file and grab what you want.


Michael Libeson
 
Net::FTP is nice and easy to use, I'd go that way

Mike

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top