If I read the man page correctly, environ
is a char**
, not a function. If you want to get var var, according to this post , you can do:
from ctypes import * libc = CDLL('libc.so.6') environ = c_char_p.in_dll(libc, 'environ')
But it returns 'c_void_p (None)' for me, I donβt know why this happens (I know that I declared only as char *
, but since it returns None, they are not for dereference).
In any case, you still have the python method:
import os print os.environ
Or, if you are looking for a specific string in an environment using ctypes, for some function you need to override the standard repeat type:
from ctypes import * libc = CDLL('libc.so.6') getenv = libc.getenv getenv.restype = c_char_p print getenv('HOME')
source share