We want a simple method to get battery level if it exists on a system regardless if its Linux, Windows, or Mac OSX.

Turns out this is pretty messy as part of it relies on the OS vendor and part is really low-level hardware implementation details.  But I thought I got all 3 major operating systems covered.

I tested Windows 7  64 bit & Linux Ubuntu 14.04 64 bit - was all worky, but Gael had different results :(

What do you get ?

kwatters

8 years 2 months ago

I tried here on win 10 , 64 bit.. but no worky   "None" was returned  (null)  

Not much debbuging info..  This was with a fresh install into a new folder with the latest.

Also of interested, the exception/stack trace showed up in the myrobotlab.log, but did NOT show up in the log service or in the java log in the python window..  not sure why the stack trace was supressed there... 

.................................................................................

[python] [INFO] exec(String) 
print Runtime.getBatteryLevel()
[python.interpreter.4] [INFO] execToString threw
.................................................................................
 
i suspect the issue is that it's not being found on the PATH ... 
 
The program is installed an available in the command prompt here:
 
C:\Windows\System32\wbem\WMIC.exe
 
but it seems like runtime is trying to find it in the current working directory for MRL.. and so it's fetting a file not found sort of exception looking in the current directory "." 

Thanks Kwatters,

I can see "C:\WINDOWS\System32\Wbem;" is one of the entries in your PATH variable ... I would have expected Apache-common-exec 'by default' to execute in the same inherited environment for which mrl is running ....

We (Gael, You, and I) are :

  • using the same version of MR
  • have the same version of Windows
  • have this executable on our system
  • are running mrl from a jar
  • are using the same script

Sooooo...  by process of elimination IT MUST BE A JAVA 8 THING ! ... cuz I'm running Java 1.7 :)

Now I'm dumping the environment and did a slight code change :

from :
exec.execute(commandline);

to:
exec.execute(commandline, EnvironmentUtils.getProcEnvironment());

As per suggestions from here :
http://stackoverflow.com/questions/2693020/commons-exec-executing-a-pro…;

Hopefully it worky !

 

hairygael

8 years 2 months ago

Gee, I wouldn't have expected this to be so difficult to set up. I fact, I initially tried to set it up myself...

I'm so glad you are on it, otherwise I would be out of charge long before it would finally work.

:)

Alessandruino

8 years 2 months ago

Worky on Mac in the debugger.... Got to see which version of Java i have...