-
Notifications
You must be signed in to change notification settings - Fork 188
Expand file tree
/
Copy pathtest-process.ts
More file actions
49 lines (41 loc) · 1.25 KB
/
test-process.ts
File metadata and controls
49 lines (41 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { exec } from 'child_process';
import { promisify } from 'util';
import fs from 'fs';
const execAsync = promisify(exec);
function isWsl(): boolean {
if (process.platform !== 'linux') return false;
try {
const version = fs.readFileSync('/proc/version', 'utf-8').toLowerCase();
return version.includes('microsoft') && version.includes('wsl');
} catch {
return false;
}
}
async function isProcessRunning(): Promise<boolean> {
try {
const platform = process.platform;
let command = '';
console.log('Platform:', platform);
console.log('Is WSL:', isWsl());
if (platform === 'win32' || isWsl()) {
const cmd = isWsl() ? '/mnt/c/Windows/System32/tasklist.exe' : 'tasklist';
command = `${cmd} /FI "IMAGENAME eq Antigravity.exe" /NH`;
} else {
command = 'pgrep -x Antigravity';
}
console.log('Command:', command);
const { stdout } = await execAsync(command);
console.log('Stdout:', stdout);
if (platform === 'win32' || isWsl()) {
return stdout.includes('Antigravity.exe');
} else {
return stdout.trim().length > 0;
}
} catch (error) {
console.error('Error:', error);
return false;
}
}
isProcessRunning().then((result) => {
console.log('Result:', result);
});