diff options
Diffstat (limited to 'Lib/test/subprocessdata')
-rw-r--r-- | Lib/test/subprocessdata/fd_status.py | 24 | ||||
-rw-r--r-- | Lib/test/subprocessdata/input_reader.py | 7 | ||||
-rw-r--r-- | Lib/test/subprocessdata/qcat.py | 7 | ||||
-rw-r--r-- | Lib/test/subprocessdata/qgrep.py | 10 |
4 files changed, 48 insertions, 0 deletions
diff --git a/Lib/test/subprocessdata/fd_status.py b/Lib/test/subprocessdata/fd_status.py new file mode 100644 index 00000000000..1f61e13a345 --- /dev/null +++ b/Lib/test/subprocessdata/fd_status.py @@ -0,0 +1,24 @@ +"""When called as a script, print a comma-separated list of the open +file descriptors on stdout.""" + +import errno +import os + +try: + _MAXFD = os.sysconf("SC_OPEN_MAX") +except: + _MAXFD = 256 + +if __name__ == "__main__": + fds = [] + for fd in range(0, _MAXFD): + try: + st = os.fstat(fd) + except OSError as e: + if e.errno == errno.EBADF: + continue + raise + # Ignore Solaris door files + if st.st_mode & 0xF000 != 0xd000: + fds.append(fd) + print(','.join(map(str, fds))) diff --git a/Lib/test/subprocessdata/input_reader.py b/Lib/test/subprocessdata/input_reader.py new file mode 100644 index 00000000000..1dc3191ad18 --- /dev/null +++ b/Lib/test/subprocessdata/input_reader.py @@ -0,0 +1,7 @@ +"""When called as a script, consumes the input""" + +import sys + +if __name__ == "__main__": + for line in sys.stdin: + pass diff --git a/Lib/test/subprocessdata/qcat.py b/Lib/test/subprocessdata/qcat.py new file mode 100644 index 00000000000..fe6f9db25c9 --- /dev/null +++ b/Lib/test/subprocessdata/qcat.py @@ -0,0 +1,7 @@ +"""When ran as a script, simulates cat with no arguments.""" + +import sys + +if __name__ == "__main__": + for line in sys.stdin: + sys.stdout.write(line) diff --git a/Lib/test/subprocessdata/qgrep.py b/Lib/test/subprocessdata/qgrep.py new file mode 100644 index 00000000000..69906379a9b --- /dev/null +++ b/Lib/test/subprocessdata/qgrep.py @@ -0,0 +1,10 @@ +"""When called with a single argument, simulated fgrep with a single +argument and no options.""" + +import sys + +if __name__ == "__main__": + pattern = sys.argv[1] + for line in sys.stdin: + if pattern in line: + sys.stdout.write(line) |