jacques has asked for the wisdom of the Perl Monks concerning the following question:

Someone is trying to convince me of the usefulness of a Win32 module that can "pause" or keep the DOS window open when a perl script is double-clicked. Normally, under Windows, when a script is double-clicked the DOS window will open and close quickly, so that anything sent to STDOUT or STDERR will not be seen (or simply flash across the screen too quickly). So this person has created a module that detects (using env variables) if the script was double-clicked and then keeps the window open until the user presses a key.

So bascially, you are looking at something like this:

print "hello\n"; print "monk\n"; pause();

My problem with this module is as follows:
- If someone wants to see any output they should execute the script at the command-line.
- There are much better ways of keeping the window open, such as this.
- You could also use sleep or send the output to another application, if it is that important.

Anyway, I just wanted to get more opinions about such a module.

Replies are listed 'Best First'.
Re: Pausing Win32 scripts
by Abigail-II (Bishop) on Sep 08, 2003 at 21:54 UTC
    I never program for Windows, so I never have to deal with this particular issue, but usually when I want to have a "pause" in my program, I just do:
    do_something (); <>; # Waits for a return. do_something_else ();

    No module needed!

    Abigail

Re: Pausing Win32 scripts
by PodMaster (Abbot) on Sep 08, 2003 at 21:59 UTC
    What module? I find such tricks irritating (if you want a commandline, use it, otherwise don't bother). To that person I offer Tutorials -> Behind the GUI, Lives the shell, cause it sounds like he's afraid of it (for any application I want to run by double clicking I never get any dos windows -- wperl.exe).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Pausing Win32 scripts
by bbfu (Curate) on Sep 09, 2003 at 05:35 UTC

    Personally, I enjoyed tye's -Mouse, and use (a slightly modified version of) it on my own computer.

    bbfu
    Black flowers blossom
    Fearless on my breath

Re: Pausing Win32 scripts
by davido (Cardinal) on Sep 09, 2003 at 03:47 UTC
    Well, if the script is intended to run as a windowed entity, and it is unlikely that whoever runs it will have time upon exit to see 'stuff' that has been sent to STDOUT and STDERR -- and this because those standard filehandles are directed toward a terminal window that is sitting behind the scenes in the background, never being utilized, it begs the question, why not redirect STDOUT and STDERR to a logfile?

    Output that goes nowhere anyone is likely to ever have the chance to see is probably "A Bad Idea", unless you're trying to use that unseen place as somewhere to /dev/null messages. But assuming those messages may have some value, put them somewhere they can be of use.

    Dave

    "If I had my life to do over again, I'd be a plumber." -- Albert Einstein

Re: Pausing Win32 scripts
by clintp (Curate) on Sep 09, 2003 at 02:19 UTC
    As annoying as it is, Windows users want to run things like this for convenience sake, so I wound up writing one. What I did was write the module so it created an object and just left it lying around. When the program exited, and all of the conditions were right (Win32, run from Explorer, etc...) it caused a pause to happen during destruction. That way I could have multiple exit points from the program and not need an explicit pause().
Re: Pausing Win32 scripts
by barbie (Deacon) on Sep 09, 2003 at 09:35 UTC
    PodMaster, you may find it irritating, that's your perogative. However, it is not always possible to use the commandline, and in those instances things like this are useful. The idea of being able to double-click an icon and it just running seems quite reasonable. I'd rather have that kind of useability than having to startup a console, navigate to the correct directory and then executing the script. Having something that can pause the window is hardly a "trick", Unix (well C) has had it for years.

    You mention wperl. I had not previously heard of this app, and found this quite interesting. However, it still does not get round the problem that I have been experiencing. Unfortunately I cannot guarantee that anything other than a basic Perl install is available.

    I am currently writing an InstallShield installation script. The basic copying/unpacking is done by InstallShield, but the detailed install and configuration is done by Perl (mainly PAR). InstallShield runs Perl in a commandline window, and if anything goes wrong you can be in a blink and you'll miss it scenario. The suggestion by davido to use logfiles is a fair one, but the message you want to appear on the screen maybe quite important for the user. Asking them to manually check logfiles after installation is not something I would recommend.

    I'm currently looking into using PerlEz.dll (see 'Execute Perl Scripts from InstallScript' heading at http://www.installsite.org/pages/en/isp_ext.htm) within InstallShield and it seems to be working. But for the time being I'm stuck with the DOS window popping up.

    --
    Barbie | Birmingham Perl Mongers | http://birmingham.pm.org/