zeroclaw-labs/zeroclaw · error · anyhow::Error

PowerShell Get-Content exited with non-zero status

Error message

PowerShell Get-Content exited with non-zero status

What it means

In follow mode, logs_windows shells out to PowerShell 'Get-Content -Tail N -Wait' against the resolved log file. A non-zero PowerShell exit is propagated as this error; follow mode otherwise blocks, so failure means the cmdlet could not open or keep reading the file.

Source

Thrown at crates/zeroclaw-runtime/src/service/mod.rs:1072

            logs_dir.display()
        );
    };

    if follow {
        // Windows: use PowerShell Get-Content -Wait for tail -f equivalent
        let status = Command::new("powershell")
            .args([
                "-Command",
                &format!(
                    "Get-Content -Path '{}' -Tail {} -Wait",
                    log_file.display().to_string(),
                    lines
                ),
            ])
            .status()
            .context("Failed to run PowerShell Get-Content")?;
        if !status.success() {
            bail!("PowerShell Get-Content exited with non-zero status");
        }
    } else {
        let status = Command::new("powershell")
            .args([
                "-Command",
                &format!(
                    "Get-Content -Path '{}' -Tail {}",
                    log_file.display().to_string(),
                    lines
                ),
            ])
            .status()
            .context("Failed to run PowerShell Get-Content")?;
        if !status.success() {
            bail!("PowerShell Get-Content exited with non-zero status");
        }
    }
    Ok(())

View on GitHub (pinned to 88bb9c8533)

Solutions

  1. Re-run 'zeroclaw service logs' after the lock or rotation clears
  2. Test manually: powershell -Command "Get-Content -Tail 50 -Wait '<logfile>'" to see the cmdlet error
  3. Fix ACLs or move the log directory to a path without spaces/special characters
Defensive patterns

Strategy: try-catch

Validate before calling

if !log_file.exists() {
    // avoid spawning PowerShell for a file that is already gone
}

Try / catch

match service::logs(&config, init, lines, true) {
    Err(err) if err.to_string().contains("PowerShell Get-Content exited with non-zero status") => {
        // likely a lock or rotation: advise retry, fall back to a non-following read
        let _ = service::logs(&config, init, lines, false);
    }
    result => result?,
}

Prevention

When it happens

Trigger: The log file is locked by another process, deleted or rotated between resolution and the Get-Content spawn, unreadable due to ACLs, or the constructed -Command string hits a path with problematic quoting.

Common situations: Log rotation while following on Windows; files locked by the daemon or backup/antivirus software; paths containing spaces or quotes breaking the inner PowerShell command line.

Related errors


AI-assisted analysis of zeroclaw-labs/zeroclaw@88bb9c8533 (2026-08-23). Data as JSON: /api/errors/1299d804958e2274. Report an issue: GitHub.