UNPKG

cc-model-switcher

Version:

A simple CLI tool to switch Claude Code AI models easily

52 lines (42 loc) 1.52 kB
const { spawn } = require('child_process'); const path = require('path'); /** * 测试spawn调用时的路径处理问题 * 功能:验证PowerShell -Command参数是否正确处理路径 * 参数:无 * 返回值:无 * 创建日期:2025-01-14 */ function testSpawnPath() { const workDir = 'E:\\GIT_CODE\\image-get\\md2xhs'; const normalizedPath = path.resolve(workDir); console.log('原始路径:', workDir); console.log('规范化路径:', normalizedPath); // 测试1: 直接使用PowerShell -Command const psCommand = `Set-Location -Path '${normalizedPath}'; echo "当前目录: $(Get-Location)"`; console.log('PowerShell命令:', psCommand); const claude1 = spawn('powershell.exe', ['-Command', psCommand], { stdio: 'inherit', shell: false }); claude1.on('error', (error) => { console.error('方法1错误:', error.message); }); claude1.on('close', (code) => { console.log('方法1退出码:', code); // 测试2: 使用cwd参数 console.log('\n--- 测试方法2: 使用cwd参数 ---'); const claude2 = spawn('powershell.exe', ['-Command', 'echo "当前目录: $(Get-Location)"'], { stdio: 'inherit', shell: false, cwd: normalizedPath }); claude2.on('error', (error) => { console.error('方法2错误:', error.message); }); claude2.on('close', (code) => { console.log('方法2退出码:', code); }); }); } testSpawnPath();