简体   繁体   中英

Get the remote python version with fabric

I am new to Fabric, and so far I am able to use all the basic functionality, connect and execute bash commands. But I am trying to execute python commands too to verify the running version and other things.

but as far as the version goes, how can I get the remote python version with fab.

UPDATE (Error details): Here is the output I got

[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.

This is probably the easiest solution:

version = run("python --version").split()[2]

Note: on my system, the first line of output is "BASHRC", which is why you need to do [2] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM