work
[pspp] / tests / ui / terminal / squish-pty.py
1 #! /usr/bin/python3
2 import os
3 import pty
4 import signal
5 import sys
6
7 def main(args):
8     if len(args) < 2:
9         sys.stderr.write('''\
10 usage: squish-pty COMMAND [ARG]...
11 Squishes both stdin and stdout into a single pseudoterminal and
12 passes it as stdin and stdout to the specified COMMAND.
13 ''')
14         return 1
15
16     status = pty.spawn(args[1:])
17     if os.WIFEXITED(status):
18         return os.WEXITSTATUS(status)
19     elif os.WIFSIGNALED(status):
20         signal.raise_signal(os.WTERMSIG(status))
21     else:
22         assert False
23
24 if __name__ == '__main__':
25     sys.exit(main(sys.argv))
26