Display error message if an error occurs on "open" command

Discussion in 'Perl Misc' started by Geek, Dec 2, 2003.

  1. Geek

    Geek Guest

    How can I get the following code to display a meaningful error message if
    the "open" command doesn't succeeed?

    $blatString = "\|C:\WINNT\SYSTEM32\blat.exe
    \"d:\temp\message_body.txt\" -t \"\" -s \"This is a
    test\" -f \"\" -i \"Web Server\" -server mail.nowhere.com
    > d:\temp\~blatoutput.txt";


    open (MAIL2, $blatString));

    I'd like something that displays the actual error encountered, not just
    something like this:

    $blatString = "\|C:\WINNT\SYSTEM32\blat.exe
    \"d:\temp\message_body.txt\" -t \"\" -s \"This is a
    test\" -f \"\" -i \"Web Server\" -server mail.nowhere.com
    > d:\temp\~blatoutput.txt";


    unless (open (MAIL2, $blatString)) {
    print "<p>Can't execute Blat</p>";
    $BlatError = 1;
    }
     
    Geek, Dec 2, 2003
    #1
    1. Advertising

  2. Geek

    Tore Aursand Guest

    On Mon, 01 Dec 2003 18:41:51 -0800, Geek wrote:
    > open (MAIL2, $blatString));
    >
    > I'd like something that displays the actual error encountered, [...]


    Use the $! operator.


    --
    Tore Aursand <>
    "To cease smoking is the easiset thing I ever did. I ought to know,
    I've done it a thousand times." -- Mark Twain
     
    Tore Aursand, Dec 2, 2003
    #2
    1. Advertising

  3. In article <>, Tore Aursand wrote:
    > On Mon, 01 Dec 2003 18:41:51 -0800, Geek wrote:
    >> open (MAIL2, $blatString));
    >>
    >> I'd like something that displays the actual error encountered, [...]

    >
    > Use the $! operator.


    s/operator/variable/;

    dha

    --
    David H. Adler - <> - http://www.panix.com/~dha/
    DHA is the "Smorax", he is friends with the Twinkies and speaks for
    the Choc-O-Diles. - Mark Rogaski
     
    David H. Adler, Dec 2, 2003
    #3
  4. Geek

    Geek Guest

    Thanks to you and David. :)

    "Tore Aursand" <> wrote in message
    news:p...
    > On Mon, 01 Dec 2003 18:41:51 -0800, Geek wrote:
    > > open (MAIL2, $blatString));
    > >
    > > I'd like something that displays the actual error encountered, [...]

    >
    > Use the $! operator.
    >
    >
    > --
    > Tore Aursand <>
    > "To cease smoking is the easiset thing I ever did. I ought to know,
    > I've done it a thousand times." -- Mark Twain
     
    Geek, Dec 2, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nick
    Replies:
    3
    Views:
    589
    Jaspreet
    Oct 12, 2005
  2. Replies:
    2
    Views:
    1,470
  3. Next
    Replies:
    1
    Views:
    431
    Alvin Bruney
    Nov 19, 2003
  4. TS
    Replies:
    2
    Views:
    264
    Walter Wang [MSFT]
    Jun 20, 2006
  5. Big Moxy
    Replies:
    14
    Views:
    239
    Bob Barrows [MVP]
    Nov 30, 2007
Loading...

Share This Page