Windows "The system cannot find the file specified" (exit 2) in CI
Windows could not start a process or open a file because the named executable or input path does not exist where it was looked up. This is the Win32 ERROR_FILE_NOT_FOUND (2).
What this error means
A step fails with the system-cannot-find-the-file message, often as a Win32Exception from a build tool or a Start-Process call. Deterministic: the same missing path fails every run.
System.ComponentModel.Win32Exception (2): The system cannot find the file
specified.
at System.Diagnostics.Process.StartWithCreateProcess(...)
##[error]Process completed with exit code 2.Common causes
The executable is not on PATH
Start-Process or a tool launching a child process resolves the exe via PATH. If the directory is not on PATH, Windows returns error 2.
An input or intermediate file is missing
A tool that opens a config, response file, or prior build output gets error 2 when that file was never produced or is in a different folder.
How to fix it
Use an absolute path to the executable
Invoke the process by full path so resolution does not depend on PATH.
Start-Process -FilePath 'C:\Program Files\dotnet\dotnet.exe' `
-ArgumentList 'build' -NoNewWindow -WaitVerify the file exists before launching
Fail with a clear message instead of a cryptic Win32 error.
$exe = 'tools\packer.exe'
if (-not (Test-Path $exe)) { throw "missing executable: $exe" }
& $exe versionHow to prevent it
- Launch processes by absolute path or after confirming the tool resolves with Get-Command, and Test-Path required input files before use.