Operating environment
Xeon E5-2620 v4 (8 cores) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 and its-devel
mpich.x86_64 3.1-5.el6 and its-devel
gcc version 4.4.7 (And gfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.Use 1.
Python 3.6.0 on virtualenv
$ touch test_original_170324
$ ln -fs test_original_170324 LN_link_170324
$ ls -l LN_link_170324
lrwxrwxrwx 1 user user 20 Mar 24 16:06 LN_link_170324 -> test_original_170324
I want to get the original link file of LN_link_170324, test_original_170324
, from a Python script.
Reference Get the return value of an external shell script (ls) with python3 Reference https://docs.python.jp/3/library/subprocess.html
test_python_170324j.py
from subprocess import getoutput
# Python 3.6.0 on virtualenv
cmd = 'ls -l LN_link_170324'
last = getoutput(cmd).split(' ')[-1]
print(last)
result
$ python test_python_170324j.py
test_original_170324
(Addition 2017/03/25)
@ komeda-shinji told me os.readlink () in Comment.
Thank you for the information.