Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Expect, STDout, and formating

by cbro (Pilgrim)
on Jun 12, 2003 at 21:03 UTC ( [id://265498]=note: print w/replies, xml ) Need Help??


in reply to Expect, STDout, and formating

Here's an example that you can port to your code:
use Expect; $exp = new Expect; $exp->log_stdout(0); $exp->log_file(\&formatoutput); $exp->spawn("/bin/sh"); $exp->send("/bin/cat /etc/passwd\n"); $exp->soft_close(); sub formatoutput { my $input = shift; # format however you'd like # e.g. $input =~ s/\$//g; # That will get rid of the $ output and leave you with # only data. You will also need to get rid of the # commands as they too will be passed to this function. # By that I mean /bin/cat /etc/passwd # You can do all types of good stuff for additional # formatting such as formline or format STDOUT_TOP = print STDOUT "\n\n$input\n\n"; # or if you used formline print STDOUT "$^A", etc. # but I'll leave the particulars to you. return; }
HTH,
Chris

Update:changed $output to $input in the print STDOUT statement...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://265498]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found