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

Hey chipmunk...

That's what's really interesting, though... the message isn't in STDERR, it's in STDOUT. I assume a similar means will work with STDOUT if I can determine what /dev/null is on a Win 9x box, right?

Alan "Hot Pastrami" Bellows

Replies are listed 'Best First'.
Re: Re: Re: Re: Small Net::SMTP problem
by chipmunk (Parson) on Dec 02, 2000 at 00:44 UTC
    Oh, weird. Happily, that makes things so much easier! Closing STDOUT and then reopening it on OLDOUT does work (at least on UNIX), and the eval isn't necessary. See if this works for you:
    open(OLDOUT, ">&STDOUT"); close(STDOUT); my $smtp = Net::SMTP->new('relay.utah-inter.net'); open(STDOUT, ">&OLDOUT");
Re: Re: Re: Re: Small Net::SMTP problem
by Hot Pastrami (Monk) on Dec 02, 2000 at 01:01 UTC
    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
      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"; };
      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.