为什么我不能在单个 Perl open 语句中将 uuencode 的输出通过管道传输到 mailx?
这是我的代码,无法正常工作:
print "To: "; my $to=<>; chomp $to;
print "From: "; my $from=<>; chomp $from;
print "Attach: "; my $attach=<>; chomp $attach;
print "Subject: "; my $subject=<>; chomp $subject;
print "Message: "; my $message=<>; chomp $message;
my $mail_fh = \*MAIL;
open $mail_fh, "uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to";
print $mail_fh $message;
close($mail_fh);
mailx 命令在命令行下工作正常,但在此 Perl 脚本上下文中却不行。
知道我缺少什么吗?
I suspect that this line's format/syntax:
open $mail_fh, "uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to";
是罪魁祸首。
Here's my code that is not working:
print "To: "; my $to=<>; chomp $to;
print "From: "; my $from=<>; chomp $from;
print "Attach: "; my $attach=<>; chomp $attach;
print "Subject: "; my $subject=<>; chomp $subject;
print "Message: "; my $message=<>; chomp $message;
my $mail_fh = \*MAIL;
open $mail_fh, "uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to";
print $mail_fh $message;
close($mail_fh);
The mailx command works fine off the command line, but not in this Perl script context.
Any idea what I'm missing?
I suspect that this line's format/syntax:
open $mail_fh, "uuencode $attach $attach |mailx -m -s \"$subject\" -r $from $to";
is the culprit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需要在开头添加一个额外的
|
即可:You just need an extra
|
at the beginning:您真的想对 uuencode 或 mailx 位使用外部二进制文件吗? UUencode 对于 pack 来说几乎是微不足道的。
Do you really want to use external binaries for either the uuencode or the mailx bit? UUencode is almost trivial with pack.
还有其他发送邮件的方式。请参阅如何发送邮件?在 perlfaq9 中。
There are other ways to send mail. See the How do I send mail? in perlfaq9.