Skip to content

Commit d24f0e7

Browse files
mipaaaPragTob
authored andcommitted
Use PowerShell instead of WMIC for system info on Windows
WMIC is being phased out. It is often no longer available by default in Windows 11 (24H2/25H2). PowerShell is present by default on all modern Windows systems, starting with Windows 7 and Windows Server 2008 R2.
1 parent 4518d60 commit d24f0e7

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

lib/benchee/system.ex

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ defmodule Benchee.System do
111111
defp cpu_speed, do: cpu_speed(os())
112112

113113
defp cpu_speed(:Windows) do
114-
parse_cpu_for(:Windows, system_cmd("WMIC", ["CPU", "GET", "NAME"]))
114+
parse_cpu_for(:Windows, system_cmd("powershell", ["-Command", "(gcim Win32_Processor).Name"]))
115115
end
116116

117117
defp cpu_speed(:macOS) do
@@ -133,10 +133,7 @@ defmodule Benchee.System do
133133
@doc false
134134
def parse_cpu_for(_, "N/A"), do: "N/A"
135135

136-
def parse_cpu_for(:Windows, raw_output) do
137-
"Name" <> cpu_info = raw_output
138-
String.trim(cpu_info)
139-
end
136+
def parse_cpu_for(:Windows, raw_output), do: String.trim(raw_output)
140137

141138
def parse_cpu_for(:macOS, raw_output), do: String.trim(raw_output)
142139

@@ -167,7 +164,7 @@ defmodule Benchee.System do
167164
defp available_memory(:Windows) do
168165
parse_memory_for(
169166
:Windows,
170-
system_cmd("WMIC", ["COMPUTERSYSTEM", "GET", "TOTALPHYSICALMEMORY"])
167+
system_cmd("powershell", ["-Command", "(gcim Win32_ComputerSystem).TotalPhysicalMemory"])
171168
)
172169
end
173170

0 commit comments

Comments
 (0)