View Single Post
  #8   (View Single Post)  
Old 11th January 2009
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Tcpdump Spy
 
Join Date: Apr 2008
Location: Netherlands
Posts: 2,243
Default

Ok, the problem with the C example was the wrong printf() statement, as anemos pointed out.

The problem with the python example was that I used the wrong type for buf, string instead of int.

For those interested, a working python example:
Code:
import ctypes

libc = ctypes.CDLL('libc.so')
size = ctypes.c_size_t()
buf = ctypes.c_int()
size.value = ctypes.sizeof(buf)
libc.sysctlbyname("hw.acpi.battery.life", ctypes.byref(buf), ctypes.byref(size), None, 0)

print buf.value
However, BSDFan666 pointed out over jabber that the apm(8) command is a more convenient and portable way of getting the same information ... Thanks!
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things.
Reply With Quote