cloudflare/cloudflared · error
error retrieving output from command '%s': %w
Error message
error retrieving output from command '%s': %w
What it means
collectMemoryInformation on Windows runs a PowerShell command (Get-CimInstance Win32_OperatingSystem | Select FreeVirtualMemory, TotalVirtualMemorySize | Format-List) and this error wraps any command.Output() failure. It means PowerShell could not be launched, the command was cancelled, or it exited non-zero — no memory stdout was produced for parsing. The wrapped command string and error reveal the exact launch/exit cause.
Source
Thrown at diagnostic/system_collector_windows.go:107
return info, err
}
func collectMemoryInformation(ctx context.Context) (*MemoryInformation, string, error) {
const (
memoryTotalPrefix = "TotalVirtualMemorySize"
memoryAvailablePrefix = "FreeVirtualMemory"
)
command := exec.CommandContext(
ctx,
"powershell",
"-Command",
"Get-CimInstance -Class Win32_OperatingSystem | Select-Object FreeVirtualMemory, TotalVirtualMemorySize | Format-List",
)
stdout, err := command.Output()
if err != nil {
return nil, "", fmt.Errorf("error retrieving output from command '%s': %w", command.String(), err)
}
output := string(stdout)
// the result of the command above will return values in bytes hence
// they need to be converted to kilobytes
mapper := func(field string) (uint64, error) {
value, err := strconv.ParseUint(field, 10, 64)
return uint64(float64(value) * kiloBytesScale), err
}
memoryInfo, err := ParseMemoryInformationFromKV(output, memoryTotalPrefix, memoryAvailablePrefix, mapper)
if err != nil {
return nil, output, err
}
// returning raw output in case other collected information
// resulted in errorsView on GitHub (pinned to 2253eeeb25)
Solutions
- Check the wrapped error: 'executable file not found' means restore Windows PowerShell (optional features) or patch the environment so powershell.exe is on PATH.
- Ensure the WMI/Winmgmt service is running: 'Get-Service winmgmt' and 'winmgmt /verifyrepository' — restart or repair the repository if broken.
- Run the exact Get-CimInstance command manually in PowerShell to see any non-zero exit cause (CIM errors surface there).
- If AppLocker/WDAC blocks powershell.exe, add an allow rule for the cloudflared process or script path.
- If the error is context deadline exceeded, investigate slow CIM/WMI startup and increase the diagnostic timeout.
Example fix
// before: only PowerShell 7 present C:\> where powershell → not found // after: restore Windows PowerShell optional feature Add-WindowsCapability -Online -Name Microsoft.Windows.PowerShell.ISE~~~~0.0.1.0 # or ensure C:\Windows\System32\WindowsPowerShell\v1.0 is on PATH
Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := exec.LookPath("powershell"); err != nil {
return fmt.Errorf("Windows PowerShell not on PATH: %w", err)
}
if svc, err := exec.Command("sc", "query", "winmgmt").Output(); err != nil || !strings.Contains(string(svc), "RUNNING") {
return fmt.Errorf("WMI service (winmgmt) not running")
} Type guard
func powershellReady() bool {
if _, err := exec.LookPath("powershell"); err != nil {
return false
}
out, err := exec.Command("powershell", "-NoProfile", "-Command", "Get-Service winmgmt").Output()
return err == nil && strings.Contains(string(out), "Running")
} Try / catch
info, raw, err := collector.Collect(ctx)
if err != nil && strings.Contains(err.Error(), "error retrieving output from command 'powershell") {
log.Warn().Err(err).Msg("Windows memory collection failed; check PowerShell and WMI health")
// retry once after restarting winmgmt, or skip the memory section
} Prevention
- Keep Windows PowerShell (powershell.exe) installed; don't remove it when adding PowerShell 7.
- Monitor the Winmgmt service health and verify the WMI repository periodically (winmgmt /verifyrepository).
- Ensure AppLocker/WDAC rules permit powershell.exe for the account running cloudflared.
- Run the Get-CimInstance query in a scheduled health check so regressions surface before diagnostics fail.
- Use bounded timeouts so slow CIM responses appear as timeouts you can act on.
When it happens
Trigger: Collect() calls collectMemoryInformation on Windows; 'powershell' is not on PATH (PowerShell removed or only pwsh installed), the Win32_OperatingSystem CIM query fails (WMI/CIM service stopped), the context deadline expires, or a security policy blocks powershell.exe.
Common situations: Systems where Windows PowerShell was uninstalled and only PowerShell 7 (pwsh.exe) exists, the WMI (Winmgmt) service disabled or broken in stripped-down Windows images, endpoint security (AppLocker/WDAC) blocking powershell.exe, or slow CIM queries exceeding the diagnostic timeout.
Related errors
- error opening file %s:%w
- couldn't parse index from timeout hop: %w
- parsing os information: %w, key=%s
- parsing memory information: %w, key=%s
- error retrieving output from command '%s': %w
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/474e77dbec8cabae.
Report an issue: GitHub.