quit when shell exits

This commit is contained in:
~d6 2023-01-21 15:58:02 -05:00
parent 3bfd045159
commit c5a850b9e1
1 changed files with 12 additions and 5 deletions

17
term.py
View File

@ -1,15 +1,15 @@
#!/usr/bin/python #!/usr/bin/python
#
# ./term.py term.rom /bin/bash
from select import select from select import select
from subprocess import Popen, PIPE, STDOUT from subprocess import Popen, PIPE, STDOUT
import sys import sys
# TODO: byte-by-byte I/O is painful. figure out better buffering # currently unbuffered
# that doesn't break everything #
# TODO: figure out a more reasonable buffering strategy
# currently line-buffered
def run(args): def run(args):
#return Popen(args, stdin=PIPE, stdout=PIPE, stderr=STDOUT, bufsize=1, universal_newlines=True)
return Popen(args, stdin=PIPE, stdout=PIPE, stderr=STDOUT, bufsize=0) return Popen(args, stdin=PIPE, stdout=PIPE, stderr=STDOUT, bufsize=0)
def main(): def main():
@ -19,6 +19,8 @@ def main():
print('') print('')
print('execute the given uxn terminal program (ROM)') print('execute the given uxn terminal program (ROM)')
print('and start a shell process (SHELL).') print('and start a shell process (SHELL).')
print('')
print('example: %s term.rom /bin/bash' % sys.argv[0])
sys.exit(1) sys.exit(1)
rom = args[0] rom = args[0]
shell = args[1] shell = args[1]
@ -42,5 +44,10 @@ def main():
else: else:
raise Exception('unexpected fileno: %d (expected %d or %d)' % (n, term_out, shell_out)) raise Exception('unexpected fileno: %d (expected %d or %d)' % (n, term_out, shell_out))
if shell.poll() is None:
shell.kill()
if term.poll() is None:
term.kill()
if __name__ == "__main__": if __name__ == "__main__":
main() main()