使用Fabric获取远程Python版本
我刚开始接触Fabric,目前已经能使用一些基本功能,比如连接和执行bash命令。不过,我也想执行一些python命令,来检查运行的版本和其他信息。
但是关于版本的问题,我想知道怎么用fab来获取远程的python版本。
更新(错误详情):
这是我得到的输出:
[192.168.3.139] run: python --version
[192.168.3.139] out: Python 2.7.1+
[192.168.3.139] out:
Traceback (most recent call last):
File "/home/mo/Projects/mazban/lib/python2.6/site-packages/fabric/main.py", line 723, in main
task(*args, **kwargs)
File "/home/mo/Projects/mazban/mazban/fabfile.py", line 203, in firstrun
version = run("python --version").split()[2]
IndexError: list index out of range
Disconnecting from 192.168.3.139... done.
1 个回答
3
这可能是最简单的解决办法:
version = run("python --version").split()[2]
注意:在我的系统上,输出的第一行是“BASHRC”,所以你需要执行 [2]
这个步骤。