如何使用python远程执行进程 [英] How to execute a process remotely using python
本文介绍了如何使用python远程执行进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 Python 连接到远程服务器并在其上执行一个进程.我希望能够获得进程的返回码和标准错误(如果有).有没有人以前做过这样的事情.我已经用 ssh 完成了,但我想从 Python 脚本中完成.
I want to connect to and execute a process on a remote server using Python. I want to be able to get the return code and stderr (if any) of the process. Has anyone ever done anything like this before. I have done it with ssh, but I want to do it from Python script.
干杯.
推荐答案
好吧,你可以从 python 调用 ssh...
Well, you can call ssh from python...
import subprocess
ret = subprocess.call(["ssh", "user@host", "program"]);
# or, with stderr:
prog = subprocess.Popen(["ssh", "user@host", "program"], stderr=subprocess.PIPE)
errdata = prog.communicate()[1]
这篇关于如何使用python远程执行进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文