const process = new Deno.Command('./test', { stdout: 'piped' }).spawn();for await (const data of process.stdout.values()){ console.log(`read ${data.length} bytes: ${data}`);}
read 4 bytes: 49,10,50,10
"1\n"
"2\n"
#include <stdio.h>#include <unistd.h>int main() { printf("1\n"); sleep(3); printf("2\n"); return 0;}
const process = new Deno.Command('./test', { stdout: 'piped' }).spawn();(async() => { const reader = process.stdout.getReader(); while(true){ const read = await reader.read(); if(read.value){ console.log(`read ${read.value.length} bytes`); } if(read.done){ console.log('read complete'); break; } }})();const status = await process.status;console.log(`process finished with code ${status.code}`);
read 4 bytesread completeprocess finished with code 0