tags:

views:

61

answers:

2

I want to send the output of a Perl file in the body of the mail. Can some one let me know how I can capture the output of the Perl which prints something on the cmd to a variable?

I am running a Perl script from a command prompt and I get the output on the command prompt itself. I want to print the output on the command prompt to the body of an email. I have the function which can send the email but don't know how to capture that output. I hope its bit clear now.

A: 

Something like:

my_variable=$(perl myperl.pl)

Example:

$ cat myperl.pl
#!/usr/bin/perl

use strict;
print "stackoverflow\n";
$ my_variable=$(perl myperl.pl)
$ echo $my_variable
stackoverflow
$ 
codaddict
+2  A: 

If you are sending the email from a perl script and want to include the body of another perl script, do:

use IPC::System::Simple 'capturex';
my $body = capturex( 'perl', '/path/to/your/script' );
ysth