diff --git a/src/gmc_con.erl b/src/gmc_con.erl index 0fde9d8..2adc68b 100644 --- a/src/gmc_con.erl +++ b/src/gmc_con.erl @@ -283,18 +283,40 @@ proc_mem() -> {unix, linux} -> {processor, Cores} = hd(erlang:system_info(cpu_topology)), P = length(Cores), - M = list_to_integer(string:trim(os:cmd("cat /proc/meminfo | grep MemTotal | awk '{print $2}'"))) * 1024, + M = s_to_i(mem, string:trim(os:cmd("cat /proc/meminfo | grep MemTotal | awk '{print $2}'"))) * 1024, {P, M}; {unix, darwin} -> - P = list_to_integer(string:trim(os:cmd("sysctl -n hw.physicalcpu"))), - M = list_to_integer(string:trim(os:cmd("sysctl -n hw.memsize"))), + P = s_to_i(cpu, string:trim(os:cmd("sysctl -n hw.physicalcpu"))), + M = s_to_i(mem, string:trim(os:cmd("sysctl -n hw.memsize"))), {P, M}; {win32, nt} -> - P = list_to_integer(os:getenv("NUMBER_OF_PROCESSORS")), - M = list_to_integer(string:trim(os:cmd("powershell -Command \"(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory\""))), + P = s_to_i(cpu, os:getenv("NUMBER_OF_PROCESSORS")), + M = win_mem(), {P, M} end. +s_to_i(Type, "") -> + default_spec(Type); +s_to_i(Type, String) -> + case is_0_9(String) of + true -> list_to_integer(String); + false -> default_spec(Type) + end. + +is_0_9("") -> + true; +is_0_9([H | T]) when $0 >= H, H >= $9 -> + is_0_9(T); +is_0_9(_) -> + false. + +default_spec(cpu) -> 1; +default_spec(mem) -> 3550722201. + +win_mem() -> + Out = os:cmd("powershell -Command \"(Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory\""), + s_to_i(mem, lists:last(string:split(Out, "\r\n", all))). + do_gajudesk() -> ok = tell(info, "Running gajudesk"),