On Windows, the return value of `cmake` config/build cannot be captured until it times out

Open 💬 7 comments Opened Mar 12, 2026 by ysysimon
💡 Likely answer: A maintainer (github-actions[bot], contributor) responded on this thread — see the highlighted reply below.

What version of the Codex App are you using (From “About Codex” dialog)?

newest

What subscription do you have?

plus

What platform is your computer?

Microsoft Windows NT 10.0.19044.0 x64

What issue are you seeing?

On Windows, the return value of cmake config/build cannot be captured until it times out. Is this a problem with CMake or with Codex shell?

What steps can reproduce the bug?

When compiling a C++ project using MSVC + Ninja + CMake on Windows, Codex will run compile or configure commands in the shell until a timeout occurs.

What is the expected behavior?

I suspect it might be because CMake uses a sub-thread for compilation, causing shell commands to not return values?

Additional information

_No response_

View original on GitHub ↗

7 Comments

github-actions[bot] contributor · 4 months ago

Potential duplicates detected. Please review them and close your issue if it is a duplicate.

  • #14035
  • #13987
  • #14220

Powered by Codex Action

ysysimon · 4 months ago

I have solved the problem; first, unified_exec must be enabled on Windows.

[features]
unified_exec = true

Then, for the MSVC toolchain, add the following content to AGENTS.md

Before any build relate execution, check the current `OS` and shell, then according the result follow the instruction below
### Windows
On `windows powershell`, use the content described below to get a correct compile env
```powershell
$procEnv = [System.Environment]::GetEnvironmentVariables('Process'); $pathValue = $procEnv['Path']; $pathUpperValue = $procEnv['PATH']; $merged = @($pathValue, $pathUpperValue) | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | ForEach-Object { $_ -split ';' } | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique; [System.Environment]::SetEnvironmentVariable('PATH', $null, 'Process'); [System.Environment]::SetEnvironmentVariable('Path', ($merged -join ';'), 'Process'); Import-Module 'C:/Program Files/Microsoft Visual Studio/<version>/Community/Common7/Tools/Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell -VsInstallPath 'C:/Program Files/Microsoft Visual Studio/<version>/Community' -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64'

At this point, the codex shell can capture the output of the cmake compilation and config commands and return immediately.

ysysimon · 4 months ago

#14398 Finding this PR may cause the above methods to fail, if this PR merged unified_exec will be unavailable until the Windows sandbox supports it.

ndk · 2 months ago

The problem still remains. Started from v0.115.0

Amoystyle · 2 months ago

This is really frustrating. I want to know if the developers plan to fix this issue.

The commands take an extremely long time to hang indefinitely in Codex CLI and the Codex extension, while they run instantly and normally in PowerShell.

The problematic commands are:

cmd /c '"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" >nul 2>&1 && cmake --build --preset msvc-debug --target test'

cmd /c build_msvc_cmake.cmd msvc-debug test

build_msvc_cmake.cmd

@echo off
setlocal EnableExtensions

for %%I in ("%~dp0..") do set "ROOT_DIR=%%~fI"
cd /d "%ROOT_DIR%"

if "%~1"=="" goto :err_usage
if "%~2"=="" goto :err_usage

set "PRESET=%~1"
set "TARGET=%~2"

echo [INFO] cleaning stale build processes...
for %%P in (cmake.exe ninja.exe cl.exe link.exe) do taskkill /F /IM %%P >nul 2>&1

set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
set "VSINSTALL="

if exist "%VSWHERE%" (
  for /f "usebackq delims=" %%I in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSINSTALL=%%I"
)

if not defined VSINSTALL if exist "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise" set "VSINSTALL=%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise"
if not defined VSINSTALL if exist "%ProgramFiles%\Microsoft Visual Studio\2022\Professional" set "VSINSTALL=%ProgramFiles%\Microsoft Visual Studio\2022\Professional"
if not defined VSINSTALL if exist "%ProgramFiles%\Microsoft Visual Studio\2022\Community" set "VSINSTALL=%ProgramFiles%\Microsoft Visual Studio\2022\Community"

if not defined VSINSTALL goto :err_vs_not_found

set "VCVARS=%VSINSTALL%\VC\Auxiliary\Build\vcvars64.bat"
if not exist "%VCVARS%" goto :err_vcvars_not_found

echo [INFO] loading MSVC environment...
call "%VCVARS%" >nul
if errorlevel 1 goto :err_vcvars_fail

set "LOG_FILE=%TEMP%\msvc-cmake-build.log"
del /q "%LOG_FILE%" >nul 2>&1

echo [INFO] building preset=%PRESET% target=%TARGET% ...
cmake --build --preset "%PRESET%" --target "%TARGET%"
set "EC=%errorlevel%"

if "%EC%"=="0" goto :build_success

echo [ERROR] build failed, exit code=%EC%.
exit /b %EC%

:build_success
echo [INFO] build succeeded.
exit /b 0

:err_usage
echo [ERROR] usage: build_msvc_cmake.cmd ^<preset^> ^<target^>
exit /b 2

:err_vs_not_found
echo [ERROR] Visual Studio install path not found.
exit /b 3

:err_vcvars_not_found
echo [ERROR] vcvars64.bat not found: "%VCVARS%"
exit /b 3

:err_vcvars_fail
echo [ERROR] failed to load MSVC env
exit /b 4
ysysimon · 2 months ago
This is really frustrating. I want to know if the developers plan to fix this issue. The commands take an extremely long time to hang indefinitely in Codex CLI and the Codex extension, while they run instantly and normally in PowerShell. The problematic commands are: cmd /c '"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" >nul 2>&1 && cmake --build --preset msvc-debug --target test' cmd /c build_msvc_cmake.cmd msvc-debug test ## build_msvc_cmake.cmd `` @echo off setlocal EnableExtensions for %%I in ("%~dp0..") do set "ROOT_DIR=%%~fI" cd /d "%ROOT_DIR%" if "%~1"=="" goto :err_usage if "%~2"=="" goto :err_usage set "PRESET=%~1" set "TARGET=%~2" echo [INFO] cleaning stale build processes... for %%P in (cmake.exe ninja.exe cl.exe link.exe) do taskkill /F /IM %%P >nul 2>&1 set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" set "VSINSTALL=" if exist "%VSWHERE%" ( for /f "usebackq delims=" %%I in ("%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath) do set "VSINSTALL=%%I" ) if not defined VSINSTALL if exist "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise" set "VSINSTALL=%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise" if not defined VSINSTALL if exist "%ProgramFiles%\Microsoft Visual Studio\2022\Professional" set "VSINSTALL=%ProgramFiles%\Microsoft Visual Studio\2022\Professional" if not defined VSINSTALL if exist "%ProgramFiles%\Microsoft Visual Studio\2022\Community" set "VSINSTALL=%ProgramFiles%\Microsoft Visual Studio\2022\Community" if not defined VSINSTALL goto :err_vs_not_found set "VCVARS=%VSINSTALL%\VC\Auxiliary\Build\vcvars64.bat" if not exist "%VCVARS%" goto :err_vcvars_not_found echo [INFO] loading MSVC environment... call "%VCVARS%" >nul if errorlevel 1 goto :err_vcvars_fail set "LOG_FILE=%TEMP%\msvc-cmake-build.log" del /q "%LOG_FILE%" >nul 2>&1 echo [INFO] building preset=%PRESET% target=%TARGET% ... cmake --build --preset "%PRESET%" --target "%TARGET%" set "EC=%errorlevel%" if "%EC%"=="0" goto :build_success echo [ERROR] build failed, exit code=%EC%. exit /b %EC% :build_success echo [INFO] build succeeded. exit /b 0 :err_usage echo [ERROR] usage: build_msvc_cmake.cmd ^<preset^> ^<target^> exit /b 2 :err_vs_not_found echo [ERROR] Visual Studio install path not found. exit /b 3 :err_vcvars_not_found echo [ERROR] vcvars64.bat not found: "%VCVARS%" exit /b 3 :err_vcvars_fail echo [ERROR] failed to load MSVC env exit /b 4 ``

Try the solution I mentioned for walk-around

Amoystyle · 2 months ago
I have solved the problem; first, unified_exec must be enabled on Windows. [features] unified_exec = true Then, for the MSVC toolchain, add the following content to AGENTS.md Before any build relate execution, check the current OS and shell, then according the result follow the instruction below ### Windows On windows powershell, use the content described below to get a correct compile env ```powershell $procEnv = [System.Environment]::GetEnvironmentVariables('Process'); $pathValue = $procEnv['Path']; $pathUpperValue = $procEnv['PATH']; $merged = @($pathValue, $pathUpperValue) | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | ForEach-Object { $_ -split ';' } | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique; [System.Environment]::SetEnvironmentVariable('PATH', $null, 'Process'); [System.Environment]::SetEnvironmentVariable('Path', ($merged -join ';'), 'Process'); Import-Module 'C:/Program Files/Microsoft Visual Studio/<version>/Community/Common7/Tools/Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell -VsInstallPath 'C:/Program Files/Microsoft Visual Studio/<version>/Community' -SkipAutomaticLocation -DevCmdArguments '-arch=x64 -host_arch=x64' At this point, the codex shell can capture the output of the cmake compilation and config commands and return immediately.

Sadly, it doesn't work.