|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
||||
sysctlbyname() On FreeBSD
I recently bought a Thinkpad T61 (Didn't go for the Dell Vermaden), but all battery indicators I could find for FreeBSD eiter do not work, or don't work as I want them to, creating a simple tray application is simple, but I'm having problems with getting the sysctl.
From the commandline: % sysctl hw.acpi.battery.life 99% means its full, so now from python, from an example found here: Code:
def CheckBatt(tray): libc = ctypes.CDLL('libc.so') size = ctypes.c_uint(0) #libc.sysctlbyname("hw.acpi.battery.life", None, ctypes.byref(size), None, 0) buf = ctypes.create_string_buffer(size.value) libc.sysctlbyname("hw.acpi.battery.life", buf, ctypes.byref(size), None, 0) print buf.value return True Hm, maybe something went wrong with ctypes? Lets try from C: Code:
#include <stdio.h> #include <sys/types.h> #include <sys/sysctl.h> int main() { size_t size; int buf; size = sizeof buf; sysctlbyname("hw.acpi.battery.life", &buf, &size, NULL, 0); printf("`%s'\n", &buf); return 0; } I am not an experienced C programmer, I usually stick to stuff like python, I'm probably doing something stupid, but I can't figure out what. Also, why does the python example linked above use two sysctlbyname() calls? It seems redundant to me...
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. |
|
|