我在远程机器上有一个python脚本,我想从本地机器执行它。它需要几个参数,这就是如果我在那台机器上运行它的方法。
python python_parallel.py --num=10 --ssh=/home/user1/path/file.txt
目前,我的本地计算机中有一个运行上述脚本的python代码:
from optparse import OptionParser
parser.add_option("-n", "--num", type="int", dest="num_spice",help="Enter the number")
parser.add_option("-s", "--ssh", dest="ssh_txt",help="Enter the path to the text file")
num_spice=options.num_spice
ssh_txt=options.ssh_txt
(options, args) = parser.parse_args()
os.system('ssh user1@10.100.10.201 python /home/user1/path/python_parallel.py --num=%s --ssh=%s' %(num_spice, ssh_txt) )
有更好的办法吗? 我尝试了这个link的解决方案,但是它给了我一个错误“ImportError:No module named ssh”
你考虑过用Fabric吗?它真的很容易使用。
我建议您查看plumbum模块来执行此类操作。
这是一种运行本地命令的非常酷和简单的方法,您可以非常容易地(通过上下文管理器)对远程命令执行同样的操作。
相关问题 更多 >
编程相关推荐