简体   繁体   中英

Python run a Linux command and then leave the terminal to user

I am writing a remote login script that should just run a command (log me in to a device via telnet or ssh) and then just leave the terminal to me.

I tried subrocess.Popen module and for windows host I managed to achieve what I needed, the script opens putty or SecureCRT via a cmd command logging me in and then stops leaving the window to me.

In Linux it's a little different though, I want the script to run a command in the terminal and then I should be able to continue working on the terminal myself. I tried subrocess with not much luck.

I can achieve this with pexpect.interact() but it seems that it will be more efficient if after logging me in the python script stopped as it is not needed anymore, if it is possible of course.

Try pwntools http://docs.pwntools.com/en/latest/intro.html#making-connections

It has a nice interactive mode.

Check the examples on the page I linked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM