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!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.