| 1 |
BEGIN { |
| 2 |
LINT = 1 |
| 3 |
|
| 4 |
# `%.*s' used for input file and for output file |
| 5 |
print "hi" > "f1" |
| 6 |
fflush("f1") |
| 7 |
getline x < "f1" |
| 8 |
print close("f1") |
| 9 |
print close("f1") |
| 10 |
fflush() |
| 11 |
|
| 12 |
# `%.*s' used for input file and input pipe |
| 13 |
# `%.*s' used for input file and two-way pipe |
| 14 |
# `%.*s' used for input pipe and two-way pipe |
| 15 |
getline data3 < "echo hello" |
| 16 |
"echo hello" |& getline data2 |
| 17 |
"echo hello" | getline data |
| 18 |
|
| 19 |
print data, data2, data3 |
| 20 |
|
| 21 |
print close("echo hello") |
| 22 |
print close("echo hello") |
| 23 |
print close("echo hello") |
| 24 |
fflush() |
| 25 |
|
| 26 |
# `%.*s' used for input file and output pipe |
| 27 |
getline x < "cat" |
| 28 |
print "foo" | "cat" |
| 29 |
print close("cat") |
| 30 |
print close("cat") |
| 31 |
fflush() |
| 32 |
|
| 33 |
# unnecessary mixing of `>' and `>>' for file `%.*s' |
| 34 |
print "foo" > "f2" |
| 35 |
print "bar" >> "f2" |
| 36 |
print close("f2") |
| 37 |
print close("f2") # -1 expected here |
| 38 |
fflush() |
| 39 |
|
| 40 |
# `%.*s' used for input pipe and output file |
| 41 |
"echo hello" | getline junk |
| 42 |
print "hello" > "echo hello" |
| 43 |
print close("echo hello") |
| 44 |
print close("echo hello") |
| 45 |
fflush() |
| 46 |
|
| 47 |
# `%.*s' used for output file and output pipe |
| 48 |
# `%.*s' used for output file and two-way pipe |
| 49 |
# `%.*s' used for output pipe and two-way pipe |
| 50 |
# Not doing |& due to race condition and signals. sigh |
| 51 |
cat = "cat" |
| 52 |
print "/bin/cat \"$@\"" > "cat" |
| 53 |
print "hello" | "cat" |
| 54 |
print close("cat") |
| 55 |
print close("cat") |
| 56 |
fflush() |
| 57 |
|
| 58 |
# 11/2021: Use a nice trick to avoid race conditions in |
| 59 |
# child processes. Thanks to Miguel Pineiro Jr. <[email protected]>. |
| 60 |
# |
| 61 |
# `%.*s' used for input pipe and output pipe |
| 62 |
pipecmd = "eval $CMD_TO_RUN" |
| 63 |
|
| 64 |
ENVIRON["CMD_TO_RUN"] = "echo hello" |
| 65 |
pipecmd | getline junk |
| 66 |
ENVIRON["CMD_TO_RUN"] = "read junk" |
| 67 |
print "hello" | pipecmd |
| 68 |
|
| 69 |
print close(pipecmd) |
| 70 |
print close(pipecmd) |
| 71 |
fflush() |
| 72 |
|
| 73 |
# `%.*s' used for output file and output pipe" |
| 74 |
BINMODE = 2 |
| 75 |
print "junk" > "cksum" # cksum is more portable than md5sum |
| 76 |
print "hello" | "cksum" |
| 77 |
print close("cksum") |
| 78 |
print close("cksum") |
| 79 |
fflush() |
| 80 |
} |