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...
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|