-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-server.js
More file actions
45 lines (41 loc) · 1.69 KB
/
Copy pathtest-server.js
File metadata and controls
45 lines (41 loc) · 1.69 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
const path = require('path');
const fs = require('fs');
const os = require('os');
const { exec } = require('child_process');
const crypto = require('crypto');
const psScriptPath = path.join(__dirname, 'dist', 'scripts', 'app-controller.ps1');
const outFile = path.join(os.tmpdir(), 'anc_' + crypto.randomBytes(4).toString('hex') + '.json');
const args = ['-Action', 'list', '-OutputFile', outFile];
const psArgs = [
'-ExecutionPolicy', 'Bypass',
'-NoProfile',
'-File', `"${psScriptPath}"`,
...args.map(a => `"${a}"`)
];
const cmd = `powershell ${psArgs.join(' ')}`;
console.log('Script path:', psScriptPath);
console.log('Output file:', outFile);
console.log('Running:', cmd);
exec(cmd, { maxBuffer: 100 * 1024 * 1024, windowsHide: true }, (error, stdout, stderr) => {
console.log('Done.');
console.log('Error:', error ? error.message.slice(0, 200) : 'none');
console.log('STDOUT length:', stdout.length);
console.log('STDOUT first 100:', JSON.stringify(stdout.slice(0, 100)));
console.log('STDERR length:', stderr.length);
console.log('STDERR first 100:', JSON.stringify(stderr.slice(0, 100)));
if (fs.existsSync(outFile)) {
const data = fs.readFileSync(outFile, 'utf8');
console.log('File length:', data.length);
console.log('First char code:', data.charCodeAt(0));
console.log('First 50 chars:', JSON.stringify(data.slice(0, 50)));
try {
const apps = JSON.parse(data);
console.log('Parse OK:', apps.length, 'apps');
} catch(e) {
console.log('Parse ERROR:', e.message.slice(0, 200));
}
fs.unlinkSync(outFile);
} else {
console.log('Output file not found!');
}
});