in reply to Re: Timed STDIN input via threads on Win32
in thread Timed STDIN input via threads on Win32

That was exactly what I did to solve the thread-safe problem. Inside the read_excel I have that require Win32::OLE line. My problem is that when the timeout expires and I am calling the read_excel sub by creating a thread, then STDIN seems to hang and I have to press enter. If I will call the sub directly, the script continues, however, the problem now becomes the thread-Win32::OLE incompatibility, making the program crash.

  • Comment on Re^2: Timed STDIN input via threads on Win32

Replies are listed 'Best First'.
Re^3: Timed STDIN input via threads on Win32
by kschwab (Vicar) on Nov 19, 2013 at 03:12 UTC
    Perhaps you could try Term::Readkey instead? It has built-in support for timeouts. It reportedly works in Win32, and would let you trigger off of a single keystroke, versus the user having to press enter.

      Tried that as well. Unfortunately, it only accepts one character input via ReadKey($timeout). ReadLine does not support > 0 (or non-blocking). The input I'm trying to get from the user can be one or more. I numbered the selection and the user can input as much numbers as there are in the selection and proceed based on his/her selection. I badly need to make this timed STDIN work because the script will be used manually as well as run as a cron/scheduled task..

        I badly need to make this timed STDIN work because the script will be used manually as well as run as a cron/scheduled task.

        Here's one thought that may or may not work. How about using command line parameters and one of the Getopt modules to specify whether the script should run in batch mode (i.e. no user input) versus interactive mode (i.e. requires user to interact with the script). Going this route would mean that you can not bother with user input for the batch mode and to wait indefinitely for user input in interactive mode. Without knowing anything further about what your full code is doing, I think that this could potentially eliminate your timeout needs.

        ReadKey in a loop until you see the enter key? (usually an odd approach, but in this case...)