我在远程计算机上有一个 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 [email protected] python /home/user1/path/python_parallel.py --num=%s --ssh=%s' %(num_spice, ssh_txt) )
有更好的方法吗?
我尝试了这个解决方案link,但它给了我一个错误“ImportError:没有名为 ssh 的模块”
我建议你看看plumbum用于执行此类操作的模块。
这是运行本地命令的一种非常酷且简单的方法,您可以非常轻松地对远程命令执行相同的操作(使用上下文管理器)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)