Ensure that interactive output appears without a one-command delay.
[pspp] / tests / ui / terminal / squish-pty.py
diff --git a/tests/ui/terminal/squish-pty.py b/tests/ui/terminal/squish-pty.py
new file mode 100644 (file)
index 0000000..53132cf
--- /dev/null
@@ -0,0 +1,26 @@
+#! /usr/bin/python3
+import os
+import pty
+import signal
+import sys
+
+def main(args):
+    if len(args) < 2:
+        sys.stderr.write('''\
+usage: squish-pty COMMAND [ARG]...
+Squishes both stdin and stdout into a single pseudoterminal and
+passes it as stdin and stdout to the specified COMMAND.
+''')
+        return 1
+
+    status = pty.spawn(args[1:])
+    if os.WIFEXITED(status):
+        return os.WEXITSTATUS(status)
+    elif os.WIFSIGNALED(status):
+        signal.raise_signal(os.WTERMSIG(status))
+    else:
+        assert False
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
+