github / github/copilot-sdk

[.NET] CreateProcess fails when Copilot CLI is installed via npm (copilot.cmd)

Đang mở
#866 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
10.5k
Fork
1.5k
Merge trung bình
1 ngày 11 giờ
Pull request đã merge (30 ngày)
127

Mô tả

## Problem

On Windows, when the Copilot CLI is installed via npm, the only executables on PATH are `copilot` (extensionless) and `copilot.cmd`. There is no `copilot.exe`.

The .NET SDK's `StartCliServerAsync` uses `ProcessStartInfo` with `UseShellExecute = false`, which calls `CreateProcess` under the hood. `CreateProcess` cannot resolve `.cmd`/`.bat` files — it only finds native executables (`.exe`, `.com`). This results in:

```
System.ComponentModel.Win32Exception (2): An error occurred trying to start process 'copilot'
with working directory '...'. The system cannot find the file specified.
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at GitHub.Copilot.SDK.CopilotClient.StartCliServerAsync(...)
```

Running `copilot` in a terminal works fine because PowerShell/cmd.exe use PATHEXT to resolve `.cmd` wrappers. But the SDK's `CreateProcess` does not.

**Output of `where.exe copilot` on affected machines:**
```
C:\ProgramData\global-npm\copilot
C:\ProgramData\global-npm\copilot.cmd
```

## This was already fixed in the Python SDK

PR #338 fixed the same issue for the Python SDK by using `shutil.which()` to resolve the full CLI path before spawning the subprocess.

## Suggested fix for .NET

The SDK already has `ResolveCliCommand` which handles `.js` files by prepending `node`:

```csharp
private static (string FileName, IEnumerable Args) ResolveCliCommand(string cliPath, IEnumerable args)
{
if (cliPath.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
{
return ("node", new[] { cliPath }.Concat(args));
}
return (cliPath, args);
}
```

A similar approach for `.cmd` files (prepending `cmd.exe /c`) would work. Alternatively, resolve the PATH using PATHEXT-aware logic before passing to `ProcessStartInfo`.

## Environment

- **SDK**: GitHub.Copilot.SDK 0.1.32 (NuGet)
- **OS**: Windows 11
- **CLI install method**: npm (global)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.