-e(如果文件存在)在perl中查找sendmail的技巧

问题描述 投票:0回答:2

[尝试测试常见的sendmail位置列表,我以为只是循环和-e测试,但是这里有些我不了解的地方,写了一些子例程来更好地解释这一点;

sub mail_z
{
my $sendmail = '/xampp/usr/lib/sendmail';  #tried with/without/ and included the .exe

if(-e $sendmail){print"found SendMail";}else{print"NOT Found SendMail";}

    open ( MAIL, "| $sendmail " );
        print MAIL "From: $sender\n";
        print MAIL "To: $recipient\n";
        print MAIL "Subject: $subject\n\n";
        print MAIL "$body\n";
        print MAIL "\n.\n";
    close ( MAIL );
}

此子的结果是它在页面上打印“找不到Found SendMail”,然后使用sendmail向我发送电子邮件。显然,它发现不是-e导致我在这里做错了吗?

string perl sendmail exists
2个回答
2
投票

凭着CPAN的力量

use Unix::Whereis;

my $sendmail = whereis('ffmpeg');

FWIW,模块使用这些测试

if ( -f $bin && -x _ && -s _ ) {
# ...

0
投票

我不了解的是,在使用[open MAIL]时,在xampp中有一个钩子可以捕获缩写的[/ xampp / usr / lib / sendmail]。它可能在那里模拟了在线Apache服务器,但是影响到-e的程度还不够。在我的xampp上sendmail的actual路径是[/xampp/usr/lib/sendmail.exe],这对两种测试都有效。注意; xampp的大多数安装中,sendmail在[xampp / sendmail / sendmail.exe]

在本地[/ xampp / usr / lib /]上执行readdir测试时,Dir向我显示了文件[sendmail.exe],但是当我在[/ usr / sbin /]中运行相同的readdir测试在线主机时,我发现了该文件被称为没有扩展名的[sendmail],并在线对[sendmail]进行了-f和-d(文件或文件夹)测试,它显示了它的文件。用于本地测试的exe。

Holli和Grinnz的回答是一个不错的替代方法,但是我需要在继续之前找出我的代码出了什么问题。

© www.soinside.com 2019 - 2024. All rights reserved.