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

Hi,

I have a script that I have that will wait for input then exit. When run from a command shell (cmd.exe), it waits fine. When I create a shortcut to the perl script, it runs but doesn't wait for input. Now, when I have the shortcut point to cmd.exe then execute the perl script, it waits perfectly. So, obviously Term::ReadKey requires some component with cmd.exe for the key notification. Does anyone know of a module that would wait for key input while running from a shortcut (without cmd.exe)?

use Term::ReadKey ReadMode('cbreak'); print " --- DONE ---\n"; my $char = ReadKey(0); ReadMode('normal')

ActiveState Perl 5.8.6

Jason L. Froebe

Team Sybase member

No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Replies are listed 'Best First'.
Re: WinXP, shortcut and waiting for user input (next steps)
by tye (Sage) on Jan 01, 2005 at 21:12 UTC

    Like Mr. Muskrat, I don't see this problem. You should probably do more debugging and provide more details.

    Does your Perl script's file name match *.pl ? What does the command assoc .pl output? If you take the part after the "=" and give it to the ftype command, what does it output? For example:

    > assoc .pl .pl=Perl > ftype Perl Perl=perl "%1" %* >

    Perhaps you somehow got *.pl to be associated with running wperl instead of perl?

    I'm tempted to mention "perldoc pl2bat" because that is what I'd use in part because what language a tool is implemented in shouldn't change how you launch it. It might solve your problem just by providing a different enough way to do it, but I doubt it will cast any light on what the source of the problem is.

    - tye        

Re: WinXP, shortcut and waiting for user input
by NetWallah (Canon) on Jan 01, 2005 at 07:28 UTC
    I have not tried this, but Win32::Console may do the trick.

    I'm inclined to think that you may be looking for a GUI application that handles keyboard events, since you do not seem to want the command shell. If this is the case, the TK modules or Win32::GUI may be the direction to take.

        ..."I don't know what the facts are but somebody's certainly going to sit down with him and find out what he knows that they may not know, and make sure he knows what they know that he may not know, and that's a good thing. I think it's a very constructive exchange," --Donald Rumsfeld

Re: WinXP, shortcut and waiting for user input
by Mr. Muskrat (Canon) on Jan 01, 2005 at 17:35 UTC

    I'm not seeing the behavior that you are. When I run the script from the command prompt, double click the file or double click a shortcut to the file, it waits for a key press (two if I press <ENTER>). WinXP Pro running AS Perl 5.8.6 build 811 with Term::ReadKey 2.21.

    By the way, you have it written to print "  --- DONE ---\n"; right before you look for a key press.

Re: WinXP, shortcut and waiting for user input
by dimar (Curate) on Jan 01, 2005 at 13:04 UTC

    If you are running XP with ActiveState, then the easiest (although not 'most aesthetically pleasing') solution may be to enclose your perl script inside "Windows Scripting Host" using the 'Perlscript' language.

    The advantage is you can give your perl code the familiar pointy-clicky shortcut-accessibility of Windows. The disadvantage is you have to use methods like WScript.Echo() instead of 'print' (since, you dont want to use cmd.exe) to display output (there are other options as well, but more tedious).

    Here's a simple hello-world style example that asks for the user name, just to show what it looks like. Not tested with Term::Readkey.

    <?xml version='1.0'?> <package> <job id="default"> <script src="vbInput.vbs" language="VBScript"></script> <script language="PerlScript"> ##<![CDATA[ $sName = vbInput('Please enter your name:','John Doe'); $WScript->Echo("Hello $sName, it is ".localtime() ); ##]]> </script> </job> </package>