fix: CLI-Pfad-Suche für Windows-Dienst verbessern + CLAUDE_CLI_PATH
- CLAUDE_CLI_PATH Umgebungsvariable als höchste Priorität bei CLI-Suche - CreateCliStartInfo() Helper dedupliziert ProcessStartInfo-Erstellung - .cmd-Wrapper-Logik entfernt (nicht benötigt) - PATH-Suche priorisiert .exe für Windows Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
9391b5a6fa
commit
1101bb83a0
1 file changed
+36
-31
@@ -35,13 +35,42 @@ public class ClaudeCliService
|
||||
public bool IsAvailable => _isAvailable;
|
||||
public string CliPath => _cliPath;
|
||||
|
||||
private ProcessStartInfo CreateCliStartInfo(List<string> args, bool redirectInput = false)
|
||||
{
|
||||
var psi = new ProcessStartInfo
|
||||
{
|
||||
FileName = _cliPath,
|
||||
RedirectStandardInput = redirectInput,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
StandardOutputEncoding = Encoding.UTF8,
|
||||
StandardErrorEncoding = Encoding.UTF8
|
||||
};
|
||||
|
||||
foreach (var arg in args)
|
||||
psi.ArgumentList.Add(arg);
|
||||
|
||||
return psi;
|
||||
}
|
||||
|
||||
private static string FindCliPath()
|
||||
{
|
||||
// 1. Expliziter Pfad über Umgebungsvariable (höchste Priorität)
|
||||
var envPath = Environment.GetEnvironmentVariable("CLAUDE_CLI_PATH");
|
||||
if (!string.IsNullOrEmpty(envPath) && File.Exists(envPath))
|
||||
return envPath;
|
||||
|
||||
// 2. Bekannte Installationspfade
|
||||
var possiblePaths = new[]
|
||||
{
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "bin", "claude"),
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "bin", "claude.exe"),
|
||||
// Windows: standalone install
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Programs", "claude-code", "claude.exe"),
|
||||
// Windows/Linux: local bin (funktioniert nur wenn Dienst unter dem richtigen User läuft)
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "bin", "claude.exe"),
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".local", "bin", "claude"),
|
||||
// Linux: system paths
|
||||
"/usr/local/bin/claude",
|
||||
"/usr/bin/claude"
|
||||
};
|
||||
@@ -52,15 +81,16 @@ public class ClaudeCliService
|
||||
return path;
|
||||
}
|
||||
|
||||
// 3. PATH-Suche
|
||||
try
|
||||
{
|
||||
var pathEnv = Environment.GetEnvironmentVariable("PATH") ?? "";
|
||||
foreach (var dir in pathEnv.Split(Path.PathSeparator))
|
||||
{
|
||||
var exePath = Path.Combine(dir, "claude");
|
||||
var exePath = Path.Combine(dir, "claude.exe");
|
||||
if (File.Exists(exePath)) return exePath;
|
||||
|
||||
exePath = Path.Combine(dir, "claude.exe");
|
||||
exePath = Path.Combine(dir, "claude");
|
||||
if (File.Exists(exePath)) return exePath;
|
||||
}
|
||||
}
|
||||
@@ -191,20 +221,7 @@ public class ClaudeCliService
|
||||
|
||||
try
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = _cliPath,
|
||||
RedirectStandardInput = true,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
StandardOutputEncoding = Encoding.UTF8,
|
||||
StandardErrorEncoding = Encoding.UTF8
|
||||
};
|
||||
|
||||
foreach (var arg in args)
|
||||
startInfo.ArgumentList.Add(arg);
|
||||
var startInfo = CreateCliStartInfo(args, redirectInput: true);
|
||||
|
||||
using var process = new Process { StartInfo = startInfo };
|
||||
|
||||
@@ -560,19 +577,7 @@ public class ClaudeCliService
|
||||
|
||||
try
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = _cliPath,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
StandardOutputEncoding = Encoding.UTF8,
|
||||
StandardErrorEncoding = Encoding.UTF8
|
||||
};
|
||||
|
||||
foreach (var arg in args)
|
||||
startInfo.ArgumentList.Add(arg);
|
||||
var startInfo = CreateCliStartInfo(args);
|
||||
|
||||
using var process = new Process { StartInfo = startInfo };
|
||||
process.OutputDataReceived += (s, e) => { if (e.Data != null) output.AppendLine(e.Data); };
|
||||
|
||||
Reference in new issue
Block a user