piping for async sub process
In Deno.process, is there a way to set its STDOUT to something I can read line by line while that primary process is still running?
readable stream, I think?const cmd = ["sh", "long-running-script"]
const proc = Deno.run({stdout: "piped" , cmd: cmd});
async function handleAll(){
const decoder = new TextDecoder()
const buf =new Uint8Array(10000);
while (true){
const n = await proc.stdout.read(buf)
if (n === null){ break;}
const outout = decoder.decode(buf)
console.log(outout.slice(0,n));
}
}
const promises = [handleAll() , proc.status()]
await Promise.allSettled(promises)async function handleAll(){
const output = await proc.stdout.pipeThrough((new TextDecoderStream()))
console.dir(output)
}whileasync function handleAll() {
const outputStream = await proc.stdout.readable.pipeThrough(
new TextDecoderStream(),
);
const r = outputStream.getReader();
let firstOutput = { done: false };
while (!firstOutput.done) {
firstOutput = await r.read();
console.log(firstOutput);
}
return r;
}async function handleAll() {
const outputStream = await proc.stdout.readable.pipeThrough(
new TextDecoderStream(),
);
for await (const firstOutput of outputStream) {
console.log(firstOutput);
}
}let firstOut;
do {
firstOut = await r.read();
} while (!firstOut.done);