in reply to Re: Re: Re: Small Net::SMTP problem
in thread Small Net::SMTP problem

Hmm, a good idea, but it still prints the "Bad command or filename". Mind you, I am only assuming that the message is not sent to STDERR because in troubleshooting, if I eval() it, it still prints that text, and $@ is clear. Also, when I don't eval() it, the script doesn't die() there, or even have a problem... it continues normally and successfully runs. Am I jumping to the wrong conclusion?

Alan "Hot Pastrami" Bellows
  • Comment on Re: Re: Re: Re: Small Net::SMTP problem

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Small Net::SMTP problem
by chipmunk (Parson) on Dec 02, 2000 at 01:10 UTC
    Oh... Then it is going to STDERR. eval {} only catches die messages; it doesn't catch warnings, which still go directly to STDERR. Try this snippet: eval { warn "Warning\n"; die "Dying\n"; };
Re: Re: Re: Re: Re: Small Net::SMTP problem
by Hot Pastrami (Monk) on Dec 02, 2000 at 01:28 UTC
    This thing is really kicking my butt... if I use the following, the "Bad command..." error still appears:
    use Net::SMTP; open(OLDOUT, ">&STDOUT"); close(STDOUT); my $smtp = Net::SMTP->new('relay.utah-inter.net'); open(STDOUT, ">&OLDOUT");
    ...and if I use this...
    use Net::SMTP; open(OLDERR, ">&STDERR"); open(STDERR, "nul"); eval { my $smtp = Net::SMTP->new('relay.utah-inter.net') }; open(STDERR, ">&OLDERR"); die $@ if $@;
    ...then another console window opens containing "Bad command or filename," and the process just runs forever until I terminate it. Crazy stuff.

    Alan "Hot Pastrami" Bellows
      Darn... Okay, how about opening STDERR to a file, then closing the file and deleting it? It's not pretty, but it may work.
      use Net::SMTP; my $tmpfile = "$ENV{TMPDIR}/stmp.$$"; # Or use a module like File::T +emp open(OLDERR, ">&STDERR"); open(STDERR, ">$tmpfile"); eval { my $smtp = Net::SMTP->new('relay.utah-inter.net') }; close(STDERR); open(STDERR, ">&OLDERR"); unlink($tmpfile); die $@ if $@;
      And here's a link to the File::Temp module.