无法启动python shell并通过Exscrip运行代码

2024-06-24 12:18:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道是否可以使用Exscript在主机中打开python shell并执行一些简单命令,例如:

a=1
print(a)

下面是我的代码的样子:

account = Account('root', 'password')
conn = SSH2()                       # We choose to use SSH2
conn.connect('1.1.1.3')     # Open the SSH connection
conn.login(account)                 # Authenticate on the remote host
conn.execute('python')              
conn.execute('a=1')
conn.execute('print(a)')
print(conn.response)

当我运行这段代码时,我的程序就挂起了。另一方面,当我运行这些命令时:

conn.execute('mkdir test')
conn.execute('ls -la')

我可以看到该目录已创建

我不完全确定这是否可行,因此任何帮助或其他建议都将不胜感激。谢谢大家!


Tags: the代码命令ssh2executeaccountrootpassword