For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2007 > can't run mailx as PERL system command









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author can't run mailx as PERL system command
Elliot Holden

2007-11-27, 10:01 pm

ok this is problem going to be real easy for one of you PERL gurus but
my little brain just can't figure it out. From the command line (Solaris
9) I can do this fine:

echo my little test | mailx -s "Test Message" email@mydomain.com

But in PERL the below code does not work:

system("echo my little test | mailx -s \"Test Message\"
email@mydomain.com");

even if I just do:

system("mailx email@mydomain.com");

it does not send the email

Now I know that mailx works perfectly fine from the command line. I am
also able to do other system commands from PERL perfectly fine. Also I
know that many of you gurus might suggest I do it a different way
because of security issues or what not but I would really like to find
out why this particular system command is not working from PERL.

Sincerely

Elliot
Tom Phoenix

2007-11-27, 10:01 pm

On 11/27/07, Elliot Holden <eh@elliotholden.com> wrote:

> system("echo my little test | mailx -s \"Test Message\"
> email@mydomain.com");


What is that command? This code should show it to you:

print "The command is: echo my little test | ";
print "mailx -s \"Test Message\" ";
print "email@mydomain.com\n";

The most frequent advice heard in this forum is to put "use strict"
and "use warnings" at the top of each file of Perl code you write. In
this case, if you turn on either warnings or strict, perl itself
should point you in the right direction. If it gives you an error
message that seems cryptic, see the full explanation in the perldiag
manpage.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training
Celejar

2007-11-27, 10:01 pm

On Tue, 27 Nov 2007 19:43:55 -0500
Elliot Holden <eh@elliotholden.com> wrote:

> But in PERL the below code does not work:
>
> system("echo my little test | mailx -s \"Test Message\"
> email@mydomain.com");
>
> even if I just do:
>
> system("mailx email@mydomain.com");


You need to escape the '@' inside the double qoutes, otherwise it will
be interpolated as the value of '@mydomain'. From 'perltrap':

> Interpolation Traps
>
> Perl4-to-Perl5 traps having to do with how things get interpolated
> within certain expressions, statements, contexts, or whatever.
>
> * "@" always interpolates an array in double-quotish strings
> @ now always interpolates an array in double-quotish strings.
>
> print "To: someone@somewhere.com\n";
>
> # perl4 prints: To:someone@somewhere.com
> # perl < 5.6.1, error : In string, @somewhere now must be written as \@somewhere
> # perl >= 5.6.1, warning : Possible unintended interpolation of @somewhere in string


I think I have this right, but I'm no perl guru.

Celejar
--
mailmin.sourceforge.net - remote access via secure (OpenPGP) email
ssuds.sourceforge.net - A Simple Sudoku Solver and Generator

Jenda Krynicky

2007-11-28, 8:00 am

From: Elliot Holden <eh@elliotholden.com>
> ok this is problem going to be real easy for one of you PERL gurus but


It's either Perl (the language) or perl (the interpreter), there is
no such thing as PERL.

> my little brain just can't figure it out. From the command line (Solaris
> 9) I can do this fine:
>
> echo my little test | mailx -s "Test Message" email@mydomain.com
>
> But in PERL the below code does not work:
>
> system("echo my little test | mailx -s \"Test Message\"
> email@mydomain.com");


Use one of the many modules available from CPAN for sending email.
MIME::Lite, Mail::Sender, Mail::Mailer, Mail::Sendmail, ... to name
just a few. It's possible that some of them are already installed.

> even if I just do:
>
> system("mailx email@mydomain.com");


If you

use strict;

you get an error that will make it clear that perl though you want to
insert the contents of array @mydomain into the doublequoted string.
You have to escape $ and @ in doublequoted strings, otherwise you do
not get theliteral $ or @ but the contents of some variable. Or an
error if you use strict and the variable was not declared.

HTH, Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com