import { spawn } from "node:child_process"; export default function pipe({ command, flags, stdin="", buffer } = {}) { return new Promise((resolve, reject) => { const child = spawn(command, flags); let stdout = (buffer?[]:""); let stderr = ""; child.stderr.on("data", d => stderr += d); child.stdout.on("data", d => (buffer? stdout.push(d):stdout+=d)); child.on("close", code => { const res = { code, stderr, stdout: (buffer?Buffer.concat(stdout):stdout) }; if (code) reject(res); else resolve(res); }); //child.stdin.setEncoding("utf-8"); child.stdin.write(stdin); child.stdin.end(); }); }