bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Reading /dev/stdin Input with a Timeout


From: Ed Morton
Subject: Re: Reading /dev/stdin Input with a Timeout
Date: Thu, 14 Dec 2023 07:02:58 -0600
User-agent: Mozilla Thunderbird

Though this doesn't work:

   GAWK_READ_TIMEOUT=1000 gawk '
        { print "You entered: " $0 }
   '

this does:

   GAWK_READ_TIMEOUT=1000 gawk '
        BEGIN {
            if ( !("-","READ_TIMEOUT") in PROCINFO ) {
                PROCINFO["-","READ_TIMEOUT"] = ENVIRON["GAWK_READ_TIMEOUT"]
            }
        }
        { print "You entered: " $0 }
   '
   gawk: cmd. line:4: fatal: error reading input file `-': Connection
   timed out

so there's a workaround, though it seems like a fix should be possible for this GAWK_READ_TIMEOUT problem (which is apparently different from John's original PROCINFO["-","READ_TIMEOUT"]  MinGW problem).

    Ed.

On 12/14/2023 4:05 AM, Ed Morton wrote:
I'm also using a 64-bit gawk (the one installed by the 64-bit cygwin setup.exe).

While this works for me (as does your original script):

    $ gawk 'BEGIN{PROCINFO["-","READ_TIMEOUT"]=1000} {print "You
    entered: " $0}'
    gawk: cmd. line:1: fatal: error reading input file `-': Connection
    timed out

none of these do, I have to interrupt each of them:

    $ GAWK_READ_TIMEOUT=1000 gawk 'BEGIN{print "GAWK_READ_TIMEOUT="
    ENVIRON["GAWK_READ_TIMEOUT"]} {print "You entered: " $0}'
    GAWK_READ_TIMEOUT=1000

    $ export GAWK_READ_TIMEOUT=1000; gawk 'BEGIN{print
    "GAWK_READ_TIMEOUT=" ENVIRON["GAWK_READ_TIMEOUT"]} {print "You
    entered: " $0}'
    GAWK_READ_TIMEOUT=1000

    $ gawk 'BEGIN{ENVIRON["GAWK_READ_TIMEOUT"]=1000; print
    "GAWK_READ_TIMEOUT=" ENVIRON["GAWK_READ_TIMEOUT"]} {print "You
    entered: " $0}'
    GAWK_READ_TIMEOUT=1000

FWIW some environment variables DO work:

    $ POSIXLY_CORRECT=1 gawk 'BEGIN{print gensub(/x/,"y",1,FS)}'
    gawk: cmd. line:1: warning: regexp constant for parameter #1
    yields boolean value
    gawk: cmd. line:1: fatal: function `gensub' not defined

    $ GAWK_MSG_SRC=1 POSIXLY_CORRECT=1 gawk 'BEGIN{print
    gensub(/x/,"y",1,FS)}'
    gawk: cmd. line:1: warning: regexp constant for parameter #1
    yields boolean value
    gawk:
    
/cygdrive/d/a/scallywag/gawk/gawk-5.3.0-1.x86_64/src/gawk-5.3.0/interpret.h:1297:cmd.
    line:1: fatal: function `gensub' not defined

Regarding your Aside, you're welcome and "Thanks for noticing me" (Eeyore).

    Ed.

On 12/13/2023 11:38 PM, J Naman wrote:
I tried with and without BEGIN{ ENVIRON["GAWK_READ_TIMEOUT"]=1000.  Did you set it before invoking gawk? Also, I am using 64-bit gawk compiled by Volker Kiefel volker.kiefel@freenet.de http://vkiefel.de/compiled-sw/gawk-5.3.0-win64.zip The benchmark tests you & I did the other day ran 6% faster under gawk 64-bit vs gawk 32-bit (eli-zaretskii, Ezwinports). I guess I was expecting a little faster, but not complaining. What I really want is access to more ram, which I get. I'll try a few other things to see how timeout works. Just to be able to match results with you and others. I can easily live without the timeout.

Aside: I see and read many things you have written about gawk up to 20 years ago. The compilation of Ed Morton's responses on Stack Overflow/stackexchange would be a great gawk guide. Thanks for years of selfless sharing! John naman



On Wed, Dec 13, 2023 at 8:27 PM Ed Morton <mortoneccc@comcast.net> wrote:

    FWIW it works for me with gawk 5.3 on cygwin.

    Just out of curiosity, do you have the same problem if you set
    the `GAWK_READ_TIMEOUT` environment variable instead of
    `PROCINFO["/dev/stdin", "READ_TIMEOUT"]`?

        Ed.

    On 12/13/2023 7:07 PM, J Naman wrote:
    Date: Thu Dec 14 2023 00:34:43 UTC
    Configuration Information [Automatically generated, do not change]:

    Gawk Version: GNU Awk 5.3.0, API 4.0
    Machine: AMD64(64-bit gawk)
    OS: Windows_NT = Win 7 [Version 6.1.7601]
    platform: mingw
    LC_ALL: C
    I have read:https://www.gnu.org/software/gawk/manual/html_node/Bugs.html
       Yes or No: Yes

    Description:
    PROCINFO["/dev/stdin", "READ_TIMEOUT"] = 1000
    getline < "/dev/stdin"
    # does not timeout in 1 second; waits (forever) until Return key is pressed
    # ERRNO is not set if timeout is exceeded
    # Ref: 4.11 Reading Input with a Timeout, p.96

    Comment: This behavior MIGHT be due to the Mingw-console and not be a bug.
    print "Hello World" >"/dev/con" works on gawk mingw platform.

    Obviously this is not a debilitating bug, but I thought that I should
    report it.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]