in reply to System Command Issues

The '<' is something that the shell interprets, but in the multi-arg form of system the shell is bypassed altogether, and '<' is being passed as another argument to mail. Try this instead:

my $address = 'myname@whatever.com'; my $subject = "Comments -- Version: $Version ID: $ID"; system("mail $address -s '$subject' < blah6.txt") == 0 or die "mail failed: $?";

Update: As ikegami's reply below alludes to, a major reason for using the multi-arg form of system is precisely to bypass the shell, and therefore avoid shell quoting headaches. The single argument form of system may not be suitable if $Version or $ID contain problematic characters. If this is the case, I would break down and read in the contents of the input file, and pipe it into the mail command from within the Perl code.

the lowliest monk

Replies are listed 'Best First'.
Re^2: System Command Issues
by ikegami (Patriarch) on Jun 08, 2005 at 20:46 UTC
    You better make sure $Version and $ID don't contain single quotes or slashes or ... if you use this version of system.
Re^2: System Command Issues
by blanket (Initiate) on Jun 08, 2005 at 20:55 UTC
    Followed your advice to the letter. I get a message sent page as I should, but the message never arrives. Any thoughts?

      That sounds to me like a bad e-mail address. If the e-mail address was given in a double-quoted string, did you escape (i.e. backslash) the @? (If not, in addition to doing that, you should be running this under strict, because under strict an unescaped @ in a double-quoted string would have most likely caused the compilation to fail, thereby alerting you to the problem; it's a good thing to do in general.) And, as ikegami noted, what are the strings in $Version and $ID?

      BTW, I tried a similar short script, and it worked fine; this is what I ran:

      use strict; use warnings; my $address = 'myaddress@myhost.com'; my $subject = 'nothing'; system( "mail $address -s $subject < random.txt" ) == 0 or die "mail failed: $?";

      the lowliest monk

        Hmm. I've tried that code as well. The "strict" and "warnings" commands are very helpful indeed. It's pointing out some mysterious errors on a particular line:

        Possible unintended interpolation of @whatever in string at myscript.pl line 158.
        Possible unintended interpolation of @whatever in string at myscript.pl line 158.
        Global symbol "@whatever" requires explicit package name at myscript.pl line 158.
        Global symbol "@whatever" requires explicit package name at myscript.pl line 158.
        Execution of myscript.pl aborted due to compilation errors.

        The line in question is a simple print command immediately following the last line of the code I am posting. Line 157 is the system() command causing all the trouble...

        use strict; use warnings; my $address = 'myemail@whatever.com'; my $subject = 'Comments Version: $version ID: $ID'; # backslash the @ sign in the address $address =~ s/@/\\$1/g; system( "mail $address -s $subject < blah6.txt" ) == 0 or die "mail failed: $?";

        By the way, $ID is a 10-character alphanumeric string, and $version is something like "5.3" or "5.4" or "Nightly" (sans quotes, of course).

        Any thoughts? I appreciate all the help so far, by the way. I'm a self-professed perl newb, and can use all the suggestions I can get. Thanks!

        --blanket