Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

One of the many things that I hate about Windows is how it automatically ("helpfully") closes DOS windows when they quit. This is most annoying when the program die()d, as you don't get a chance to read the error message. So here's a snippet that detects if the program was double-clicked, or run from a command line, and alters %SIG{__DIE__} appropriatly.

Of course, Windows 9* does this differently than Windows NT/2000, so there are two different environment variables that get checked. Actually, I only had a Windows 98 and a Windows 2000 machine to test this on, so /msg me if this works / doesn't work on Windows 95 or NT.
$SIG{__DIE__} = sub { # PROMPT is for NT/2000, CMDLINE is for 95/98 return unless !defined $ENV{PROMPT} or (defined $ENV{CMDLINE} and $E +NV{CMDLINE} eq 'WIN'); print shift,"This window will close in 10 seconds." and sleep 10 and + exit; } if $^O =~ /Win32/;

Update: Per tye's suggestion, I moved the return unless $^O =~ /Win32/ outside of the __DIE__ assignment, so the handler is not even changed if we're not under Windows.

Update the second: A fellow monk has made this code into a module and put it on CPAN as Win32::Die. Check it out!


In reply to Watching Perl die() under Win32 by Chmrr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found