简体   繁体   English

Python 在 Windows 上操作命令提示符

[英]Python manipulating command prompt on windows

I would like to open a cmd and log in a computer by ssh我想打开一个cmd并通过ssh登录计算机

import os os.system('cmd /c "plink -batch -ssh root@host -pw password"')

after this i want to interact with that cmd (kind of echo things in it) so, after ssh give it "telnet" command and enter, after username, and pw在此之后,我想与该 cmd 进行交互(其中的某种回显),因此,在 ssh 之后给它“telnet”命令并在用户名和密码之后输入

i have already tried subprocess.Popen but i cant solve to give a command and wait, and give the next command, and telnet does not support to give password in cmd我已经尝试过subprocess.Popen但我无法解决给出命令并等待,然后给出下一个命令,并且 telnet 不支持在 cmd 中给出密码

If any other solution is suaitable, its okay for me, im just trying to solve it this way如果任何其他解决方案是合适的,对我来说没问题,我只是想以这种方式解决它

Thanks for anwers in advance!感谢您提前回答!

Instead of using subprocess to ssh into a machine use paramiko .使用 paramiko 代替使用 subprocess ssh 进入机器。 It's better and more secure.它更好,更安全。 Have a look at this paramiko tutorial看看这个paramiko 教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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