0

I'm doing a project at work were I need to get the version of Java for 100's of servers. I been using readlink, but that gives me full path for the link. I'm trying to figured out a way to only get the last directory using Python.

>>> f = os.system('readlink  /dir/dir/dir/java')
/dir/dir/dir/dir/jdk

I need the output to only be JDK.

Celeo
  • 5,583
  • 8
  • 39
  • 41
milo
  • 33
  • 6

1 Answers1

0

After some further research I figured it out. Once I got the output from os.readlink I then took the output and got the basename:

>>> f = os.readlink('/dir/dir/dir/java')
>>> java_version = os.path.basename(f)
'java'
Celeo
  • 5,583
  • 8
  • 39
  • 41
milo
  • 33
  • 6