forked from KushagraSinha2002/Resourceium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
53 lines (45 loc) · 1.65 KB
/
test.js
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
50
51
52
53
// @ts-check
const { spawn } = require('child_process');
async function main() {
await new Promise((resolve, reject) => {
const mark = "4c9babf79fc6";
const child = spawn("/bin/bash", [...["-ilc"], `'${process.execPath}' -p '"${mark}" + JSON.stringify(process.env) + "${mark}"'`], {
detached: true,
stdio: ['ignore', 'pipe', 'pipe'],
env: {
...process.env,
ELECTRON_RUN_AS_NODE: '1',
ELECTRON_NO_ATTACH_CONSOLE: '1'
}
});
child.on('error', err => {
console.error('getUnixShellEnvironment#errorChildProcess', err);
resolve({});
});
const buffers = [];
child.stdout.on('data', b => {
buffers.push(b);
});
const stderr = [];
child.stderr.on('data', b => {
stderr.push(b);
});
child.on('exit', (code, signal) => {
console.info('getUnixShellEnvironment#exit', code, signal);
});
child.on('close', (code, signal) => {
console.info('getUnixShellEnvironment#close', code, signal);
const raw = Buffer.concat(buffers).toString('utf8');
console.info('getUnixShellEnvironment#raw', raw);
const stderrStr = Buffer.concat(stderr).toString('utf8');
if (stderrStr.trim()) {
console.info('getUnixShellEnvironment#stderr', stderrStr);
}
if (code || signal) {
return reject(new Error(`Failed to get environment (code ${code}, signal ${signal})`));
}
resolve();
});
});
}
main();