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

I have an executable created with perlapp. When I start it a dos window appears and I log the progress in the window. When I get an error, I display the error message and have the command "my $input = <> ;" in an attempt to keep the window open until the user sees it. However, the window closes immediately. What can I do to keep it open until I get user input?

Replies are listed 'Best First'.
Re: dos window
by xdg (Monsignor) on Nov 28, 2007 at 15:37 UTC

    While you have a console window, are you sure it's interactive? (I.e. does it have STDIN connected?)

    As an alternative, if you just want to show an error dialog (and don't need actual input back), you might consider Win32 and Win32::MsgBox() instead.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: dos window
by Corion (Patriarch) on Nov 28, 2007 at 15:39 UTC

    tye wrote -Mouse to deal with that. But, how do you "display the error message" ? If you use die "error message", your program terminates and the lines waiting for user acknowledgement won't be executed.

    You could put the "wait for input" stuff into an END{} block...

Re: dos window
by cammac (Acolyte) on Nov 28, 2007 at 16:05 UTC
    if ($course eq "ERROR") { print "Fatal Error - see errorLog.txt for details \n" ; print "Hit 'ENTER' to quit\n" ; my $temp = <> ; # wait for operator input exit ; } I'm not using "die"
      One of the problems with using STDIN to pause a program is that input is often buffered. Thus you may actually be getting data that was previously entered when you are attempting to pause. You can test this by adding this change to your program:
      if ($course eq "ERROR") { print "Fatal Error - see errorLog.txt for details \n" ; print "Hit 'ENTER' to quit\n" ; my $temp = <> ; warn "\n**$temp**\n";#show what was read from STDIN sleep 5;#give yourself time to see it }

      If the Win32 package is available and a popup is permissable, try the Win32::MsgBox() function mentioned above as an alternative. It is a better solution to this problem.
Re: dos window
by KurtSchwind (Chaplain) on Nov 28, 2007 at 16:39 UTC

    Instead of starting it by 'double clicking', start up a windows command shell. Start the dos shell first and then start the app from there.

    Start -> Run -> "cmd"

    --
    I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.

      Or the thing you double click could "cmd /k perl script.pl". The /k option causes the CMD to stay after the command has exited.

      The OP may not want to burden the user with having to type "exit", though the cmd window can (usually) be closed with the 'x' in the top right corner.


      I humbly seek wisdom.