Tuesday, July 24, 2012

WLST (python) find script folder

this will return the folder from which WLST is run, not the script folder:

import os
print os.getcwd()



this seems to return the FULL PATH of the script:
print sys.argv[0]

then with:

import os
print os.path.dirname(sys.argv[0])

you can get the directory

(update: sys.argv[0] contains only the filename, not the full path, if you run WLST from the same location as the script file)

sys.argv[0] = createDatasourcesFromCMDB.py
os.path.dirname(sys.argv[0]) =
os.getcwd()=/home/soa/proton
os.path.realpath(os.path.dirname(sys.argv[0])) = /home/soa/proton

So the only thing that really works under all circumstances is

os.path.realpath(os.path.dirname(sys.argv[0]))

No comments: