-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-spawn.js
More file actions
28 lines (22 loc) · 877 Bytes
/
Copy pathtest-spawn.js
File metadata and controls
28 lines (22 loc) · 877 Bytes
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
import { spawn } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Test 1: Basic spawn
const scriptPath = path.resolve(__dirname, 'scripts', 'discover-cli-tools.js');
console.log('Script path:', scriptPath);
const child = spawn('node', ['-e', 'console.log("line1"); setTimeout(() => console.log("line2"), 1000); setTimeout(() => console.log("line3"), 2000)'], {
stdio: ['ignore', 'pipe', 'pipe'],
env: process.env,
});
child.stdout.on('data', (chunk) => {
const text = chunk.toString();
console.log('STDOUT:', JSON.stringify(text.slice(0, 100)));
});
child.stderr.on('data', (chunk) => {
console.log('STDERR:', JSON.stringify(chunk.toString().slice(0, 100)));
});
child.on('close', (code) => {
console.log('EXIT CODE:', code);
process.exit(code || 0);
});