mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
fix(shell-utils): resolve command detection on Ubuntu by using shell for builtins (#1123)
This commit is contained in:
@@ -517,24 +517,39 @@ export function resolveCommandPath(command: string): {
|
|||||||
try {
|
try {
|
||||||
const isWin = process.platform === 'win32';
|
const isWin = process.platform === 'win32';
|
||||||
|
|
||||||
const checkCommand = isWin ? 'where' : 'command';
|
if (isWin) {
|
||||||
const checkArgs = isWin ? [command] : ['-v', command];
|
const checkCommand = 'where.exe';
|
||||||
|
const checkArgs = [command];
|
||||||
|
|
||||||
let result: string | null = null;
|
let result: string | null = null;
|
||||||
try {
|
try {
|
||||||
result = execFileSync(checkCommand, checkArgs, {
|
result = execFileSync(checkCommand, checkArgs, {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
shell: isWin,
|
shell: false,
|
||||||
}).trim();
|
}).trim();
|
||||||
} catch {
|
} catch {
|
||||||
console.warn(`Command ${checkCommand} not found`);
|
return { path: null, error: undefined };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!result) return { path: null, error: undefined };
|
return result ? { path: result } : { path: null };
|
||||||
if (!isWin) {
|
} else {
|
||||||
|
const shell = '/bin/sh';
|
||||||
|
const checkArgs = ['-c', `command -v ${escapeShellArg(command, 'bash')}`];
|
||||||
|
|
||||||
|
let result: string | null = null;
|
||||||
|
try {
|
||||||
|
result = execFileSync(shell, checkArgs, {
|
||||||
|
encoding: 'utf8',
|
||||||
|
shell: false,
|
||||||
|
}).trim();
|
||||||
|
} catch {
|
||||||
|
return { path: null, error: undefined };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!result) return { path: null, error: undefined };
|
||||||
accessSync(result, fsConstants.X_OK);
|
accessSync(result, fsConstants.X_OK);
|
||||||
|
return { path: result, error: undefined };
|
||||||
}
|
}
|
||||||
return { path: result, error: undefined };
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
path: null,
|
path: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user