import { spawn } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import path from 'node:path';
const root = (path.dirname(fileURLToPath(import.meta.url)));
const exe = path.join(root, 'target', 'debug', 'consolex.exe');
const args = process.argv.slice(2);
console.log(`spawning: ${exe} ${args.join(' ')}`);
const child = spawn(exe, args, { windowsHide: false });
let stdout = '';
let stderr = '';
child.stdout.on('data', (d) => (stdout += d));
child.stderr.on('data', (d) => (stderr += d));
child.on('close', (code, signal) => {
console.log('exit code:', code, signal ? `signal: ${signal}` : '');
if (stdout) console.log('stdout:', JSON.stringify(stdout));
if (stderr) console.log('stderr:', JSON.stringify(stderr));
if (!stdout && !stderr) console.log('(no captured output)');
});