我有一个带有.bat
一些参数的文件,并使用python连接到腻子。以下是参考代码。
pushd c:
start /min Putty.exe -load SessionName -l UserName -pw Password
我正在putty1.bat
使用python调用文件,os.system
如下所述:
os.system('putty1.bat')
我已经看到了一些与之相关的参考,subprocess
但是它并没有帮助我如何传递上述参数。
提前致谢。
您可以使用Plink
哪个是命令行应用程序。这里更多信息
import subprocess
sp = subprocess.Popen(['plink', '-ssh', '-l', 'username', '-pw', 'password', 'SessionName'], \
shell = False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
sp.communicate('lmstat -a\nexit\n'.encode())
或者尝试使用paramiko
import paramiko
import socket
class Point:
def __init__(self,host,username,password,port):
self.host = host
self.username = username
self.password = password
self.port = port
def connect(self):
"""Login to the remote server"""
print("Establishing ssh connection")
self.client = paramiko.SSHClient()
self.client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connect to the server
self.client.connect(hostname=self.host, port=self.port, username=self.username, password=self.password,
timeout=1000, allow_agent=False, look_for_keys=False)
print("Connected to the server", self.host)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句