LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python - make curses play nice w/ os.system() (https://www.linuxquestions.org/questions/programming-9/python-make-curses-play-nice-w-os-system-291519/)

datadriven 02-17-2005 03:31 PM

python - make curses play nice w/ os.system()
 
Hey guys. I've been looking all over to the answer to this but most search engines just turn up a lot of links to the same 2 or 3 tutorials. I'm writing a backup program in python, and decided to put a curses interface on it, but don't know how to run system commands without ending the curses window. e.g.

Code:

def set_remote_keys(Window):
        global REMOTE_MACHINE
        curses.endwin() # if anybody know a way around this please let me know
        os.system("ssh-keygen -t rsa")
        os.system("ssh " + REMOTE_MACHINE + " \"mkdir .ssh;exit;\"")
        os.system("scp ~/.ssh/id_rsa.pub " + REMOTE_MACHINE + ":.ssh/extra_keys2")
        os.system("ssh " + REMOTE_MACHINE + " \"cat .ssh/extra_keys2 >> .ssh/authorized_keys2;rm .ssh/extra_keys2;exit;\"")
        os.system("ssh " + REMOTE_MACHINE + " \"chmod 700 .ssh;exit;\"")
        curses.wrapper(Main)

In the example, the system commands set up ssh keys on the remote machine. They require that the user hit enter 3 or 4 times. How can I output the text and get the necessary input without ending the curses window. I tried using addstr() & getstr() but I end up with either an error message or the program just hanging. I'm still kind of new to python, and I'm hoping that there's just something simple that I'm missing.


All times are GMT -5. The time now is 04:33 PM.