mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
fix(process-utils): fix bug that prevented start-up when running process walking command fails (#7757)
This commit is contained in:
@@ -24,39 +24,44 @@ async function getProcessInfo(pid: number): Promise<{
|
|||||||
name: string;
|
name: string;
|
||||||
command: string;
|
command: string;
|
||||||
}> {
|
}> {
|
||||||
const platform = os.platform();
|
try {
|
||||||
if (platform === 'win32') {
|
const platform = os.platform();
|
||||||
const powershellCommand = [
|
if (platform === 'win32') {
|
||||||
'$p = Get-CimInstance Win32_Process',
|
const powershellCommand = [
|
||||||
`-Filter 'ProcessId=${pid}'`,
|
'$p = Get-CimInstance Win32_Process',
|
||||||
'-ErrorAction SilentlyContinue;',
|
`-Filter 'ProcessId=${pid}'`,
|
||||||
'if ($p) {',
|
'-ErrorAction SilentlyContinue;',
|
||||||
'@{Name=$p.Name;ParentProcessId=$p.ParentProcessId;CommandLine=$p.CommandLine}',
|
'if ($p) {',
|
||||||
'| ConvertTo-Json',
|
'@{Name=$p.Name;ParentProcessId=$p.ParentProcessId;CommandLine=$p.CommandLine}',
|
||||||
'}',
|
'| ConvertTo-Json',
|
||||||
].join(' ');
|
'}',
|
||||||
const { stdout } = await execAsync(`powershell "${powershellCommand}"`);
|
].join(' ');
|
||||||
const output = stdout.trim();
|
const { stdout } = await execAsync(`powershell "${powershellCommand}"`);
|
||||||
if (!output) return { parentPid: 0, name: '', command: '' };
|
const output = stdout.trim();
|
||||||
const {
|
if (!output) return { parentPid: 0, name: '', command: '' };
|
||||||
Name = '',
|
const {
|
||||||
ParentProcessId = 0,
|
Name = '',
|
||||||
CommandLine = '',
|
ParentProcessId = 0,
|
||||||
} = JSON.parse(output);
|
CommandLine = '',
|
||||||
return { parentPid: ParentProcessId, name: Name, command: CommandLine };
|
} = JSON.parse(output);
|
||||||
} else {
|
return { parentPid: ParentProcessId, name: Name, command: CommandLine };
|
||||||
const command = `ps -o ppid=,command= -p ${pid}`;
|
} else {
|
||||||
const { stdout } = await execAsync(command);
|
const command = `ps -o ppid=,command= -p ${pid}`;
|
||||||
const trimmedStdout = stdout.trim();
|
const { stdout } = await execAsync(command);
|
||||||
const ppidString = trimmedStdout.split(/\s+/)[0];
|
const trimmedStdout = stdout.trim();
|
||||||
const parentPid = parseInt(ppidString, 10);
|
const ppidString = trimmedStdout.split(/\s+/)[0];
|
||||||
const fullCommand = trimmedStdout.substring(ppidString.length).trim();
|
const parentPid = parseInt(ppidString, 10);
|
||||||
const processName = path.basename(fullCommand.split(' ')[0]);
|
const fullCommand = trimmedStdout.substring(ppidString.length).trim();
|
||||||
return {
|
const processName = path.basename(fullCommand.split(' ')[0]);
|
||||||
parentPid: isNaN(parentPid) ? 1 : parentPid,
|
return {
|
||||||
name: processName,
|
parentPid: isNaN(parentPid) ? 1 : parentPid,
|
||||||
command: fullCommand,
|
name: processName,
|
||||||
};
|
command: fullCommand,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} catch (_e) {
|
||||||
|
console.debug(`Failed to get process info for pid ${pid}:`, _e);
|
||||||
|
return { parentPid: 0, name: '', command: '' };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +174,6 @@ async function getIdeProcessInfoForWindows(): Promise<{
|
|||||||
* top-level ancestor process ID and command as a fallback.
|
* top-level ancestor process ID and command as a fallback.
|
||||||
*
|
*
|
||||||
* @returns A promise that resolves to the PID and command of the IDE process.
|
* @returns A promise that resolves to the PID and command of the IDE process.
|
||||||
* @throws Will throw an error if the underlying shell commands fail.
|
|
||||||
*/
|
*/
|
||||||
export async function getIdeProcessInfo(): Promise<{
|
export async function getIdeProcessInfo(): Promise<{
|
||||||
pid: number;
|
pid: number;
|
||||||
|
|||||||
Reference in New Issue
Block a user