{"record":{"id":"8d1b0e249bde9b75","repo":"FuelLabs/sway","slug":"failed-to-execute-tasklist-command","errorCode":null,"errorMessage":"Failed to execute tasklist command","messagePattern":"Failed to execute tasklist command","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"forc-util/src/fs_locking.rs","lineNumber":65,"sourceCode":"            .arg(\"-p\")\n            .arg(pid.to_string())\n            .output()\n            .expect(\"Failed to execute ps command\");\n\n        let output_str = String::from_utf8_lossy(&output.stdout);\n        output_str.contains(&format!(\"{pid} \"))\n    }\n\n    #[cfg(target_os = \"windows\")]\n    fn is_pid_active(pid: usize) -> bool {\n        // Not using sysinfo here because it has compatibility issues with fuel.nix\n        // https://github.com/FuelLabs/fuel.nix/issues/64\n        use std::process::Command;\n        let output = Command::new(\"tasklist\")\n            .arg(\"/FI\")\n            .arg(format!(\"PID eq {}\", pid))\n            .output()\n            .expect(\"Failed to execute tasklist command\");\n\n        let output_str = String::from_utf8_lossy(&output.stdout);\n        // Check if the output contains the PID, indicating the process is active\n        output_str.contains(&format!(\"{}\", pid))\n    }\n\n    /// Removes the lock file if it is not locked or the process that locked it is no longer active\n    pub fn release(&self) -> io::Result<()> {\n        if self.is_locked() {\n            Err(io::Error::other(format!(\n                \"Cannot remove a dirty lock file, it is locked by another process (PID: {:#?})\",\n                self.get_locker_pid()\n            )))\n        } else {\n            self.remove_file()?;\n            Ok(())\n        }\n    }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/FuelLabs/sway/blob/47e5e902faa42baf652dd6a0c88cd23390c1a614/forc-util/src/fs_locking.rs#L47-L83","documentation":"Windows counterpart of the PID liveness check in forc-util's file locking: is_pid_active runs `tasklist /FI \"PID eq <pid>\"` and this expect panics when tasklist.exe cannot be spawned. As on Unix, the check only runs when an existing lock file's staleness must be determined.","triggerScenarios":"A lock file is present and the environment cannot spawn tasklist.exe: stripped-down Windows containers (Nano Server style images without the full toolset), AppContainer/restricted tokens denying execute, antivirus or policy blocking CreateProcess, or corrupted System32 tooling.","commonSituations":" forc build on Windows Server Core/Nano container images; CI runners with hardened process-creation policies; leftover lock files from a forc process that was force-killed.","solutions":["Run builds on a Windows image that includes tasklist.exe (full/Server Core rather than Nano-style minimal images).","Remove the stale lock file under the package's out/ directory so the PID check is skipped.","Adjust sandbox/AV policy to allow spawning tasklist.exe from build processes."],"exampleFix":"# before\n# Windows Nano Server container + stale .forc-lock -> panic \"Failed to execute tasklist command\"\n# after\n# use mcr.microsoft.com/windows/servercore (has tasklist) and delete stale lock:\nRemove-Item -Recurse out\\*.forc-lock; forc build","handlingStrategy":"validation","validationCode":"# PowerShell guard on Windows before forc build\nif (-not (Get-Command tasklist -ErrorAction SilentlyContinue)) {\n  Write-Error \"tasklist.exe unavailable; use a fuller Windows image or fix the sandbox\"; exit 1\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer Windows Server Core images over Nano-style minimal images for builds.","Delete stale out/**/.forc-lock files after force-killing forc.","Allow tasklist.exe in AV/AppLocker policy for build agents."],"tags":["rust","forc","forc-util","file-locking","panic","windows","tasklist","environment"],"backgroundTag":null,"analyzedSha":"47e5e902faa42baf652dd6a0c88cd23390c1a614","analyzedAt":"2026-08-16T07:57:45.555Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}