Debian Codegraph @

test/timeout.awk

raw
1 BEGIN {
2 cmd = "echo hello; sleep 1; echo goodbye"
3
4 print "With timeouts"
5 PROCINFO[cmd, "READ_TIMEOUT"] = 400
6 while ((rc = (cmd | getline x)) > 0)
7 print x
8 if (rc < 0)
9 print rc, (PROCINFO["errno"] != 0), (ERRNO != "")
10 print (close(cmd) != 0)
11
12 PROCINFO[cmd, "RETRY"]
13 print ""
14 print "With timeouts and retries"
15 while (((rc = (cmd | getline x)) > 0) || (rc == -2)) {
16 if (rc > 0) {
17 print x
18 n = 0
19 }
20 else
21 print ++n, "timed out; trying again"
22 }
23 if (rc < 0)
24 print rc, (PROCINFO["errno"] != 0), (ERRNO != "")
25 print (close(cmd) != 0)
26 }