Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/main/ts/ps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ const IS_WIN = process.platform === 'win32'
const WMIC_INPUT = 'wmic process get ProcessId,ParentProcessId,CommandLine'
const isBin = (f: string): boolean => {
if (f === '') return false
if (!f.includes('/')) return true
if (!f.includes('\\')) return true
if (!f.includes('/') && !f.includes('\\')) return true
if (f.length > 3 && f[0] === '"')
return f[f.length - 1] === '"'
? isBin(f.slice(1, -1))
: false
if (!fs.existsSync(f)) return false

const stat = fs.lstatSync(f)
return stat.isFile() || stat.isSymbolicLink()
try {
if (!fs.existsSync(f)) return false
const stat = fs.lstatSync(f)
return stat.isFile() || stat.isSymbolicLink()
} catch {
return false
}
}

export type TPsLookupCallback = (err: any, processList?: TPsLookupEntry[]) => void
Expand Down Expand Up @@ -290,8 +292,8 @@ export const formatOutput = (data: TIngridResponse): TPsLookupEntry[] =>

if (pid && cmd.length > 0) {
const c = (cmd.findIndex((_v, i) => isBin(cmd.slice(0, i).join(' '))))
const command = cmd.slice(0, c).join(' ')
const args = cmd.length > 1 ? cmd.slice(c) : []
const command = (c === -1 ? cmd: cmd.slice(0, c)).join(' ')
const args = c === -1 ? [] : cmd.slice(c)

m.push({
pid,
Expand Down
7 changes: 4 additions & 3 deletions src/test/legacy/test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,18 @@ describe('test', function () {
it('by id', function (done) {
ps.lookup({pid: pid}, function (err, list) {
assert.equal(list.length, 1);
assert.equal(list[0].arguments[0], serverPath);
assert.ok(list[0].arguments.includes(serverPath));

done();
});
});

it('by command & arguments', function (done) {
ps.lookup({command: '.*(node|iojs).*', arguments: 'node_process_for_test'}, function (err, list) {
const [found] = list
Copy link

Copilot AI Jul 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] A semicolon is missing at the end of this declaration; adding it would improve consistency with the surrounding code style.

Suggested change
const [found] = list
const [found] = list;

Copilot uses AI. Check for mistakes.
assert.equal(list.length, 1);
assert.equal(list[0].pid, pid);
assert.equal(list[0].arguments[0], serverPath);
assert.equal(found.pid, pid);
assert.ok(found.arguments.includes(serverPath));
done();
});
});
Expand Down