in

Python – interactive ZSH shell


I have this code which drops into a shell when executed via terminal:

command = ['zsh', '--no-rcs']
env_vars = os.environ.copy()
try:

        p = Popen(command,
                preexec_fn=os.setsid,
                stdin=fd_new,
                stdout=fd_new,
                stderr=fd_new,
                env=env_vars,
                universal_newlines=True)

        while p.poll() is None:
            r, w, e = select.select([sys.stdin, main_fd], [], [])
            if sys.stdin in r:
                d = os.read(sys.stdin.fileno(), 10240)
                os.write(main_fd, d)
            elif main_fd in r:
                o = os.read(main_fd, 10240)
                if o:
                    os.write(sys.stdout.fileno(), o)
    finally:

        termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty)

It works, however when I type “exit” in the new shell it does not exit, I have to press the enter key once for it to then exit the new shell.
Why is that?



Source: https://stackoverflow.com/questions/70543176/python-interactive-zsh-shell

How to add a new column with the correct order in awk taking into account that the same position may be repeated

The Overflow #106: The most lightweight “framework”: VanillaJS