Kay
Kay17mo ago

Log Deno.command process output

i need to execute a command wich will keep running until stopped and log the output. i found this but it dosnt work
const command = new Deno.Command(
"java",
{
args: [
"-Xms512M",
"-Xmx512M",
"-XX:+UseG1GC",
"-XX:G1HeapRegionSize=4M",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+ParallelRefProcEnabled",
"-XX:+AlwaysPreTouch",
"-jar",
"proxy.jar"
],
stdout: "piped",
stdin: "piped",
stderr: "piped",
},
);
const process = command.spawn();
for await (const line of readLines(process.stdout)) {
emit_console_out(line);
}
const command = new Deno.Command(
"java",
{
args: [
"-Xms512M",
"-Xmx512M",
"-XX:+UseG1GC",
"-XX:G1HeapRegionSize=4M",
"-XX:+UnlockExperimentalVMOptions",
"-XX:+ParallelRefProcEnabled",
"-XX:+AlwaysPreTouch",
"-jar",
"proxy.jar"
],
stdout: "piped",
stdin: "piped",
stderr: "piped",
},
);
const process = command.spawn();
for await (const line of readLines(process.stdout)) {
emit_console_out(line);
}
this says: Argument of type 'ReadableStream<Uint8Array>' is not assignable to parameter of type 'Reader'. Property 'read' is missing in type 'ReadableStream<Uint8Array>' but required in type 'Reader' and i know that process.stdout has a getReader but that dosnt seem to work either
3 Replies
SyrupThinker
SyrupThinker17mo ago
You could use https://deno.land/std@0.195.0/streams/mod.ts?s=TextLineStream for directly using the ReadableStream. Alternatively you could use https://deno.land/std@0.195.0/streams/mod.ts?s=readerFromStreamReader to create a Reader compatible with readLines.
Kay
KayOP17mo ago
alr thx il look into that
wobsoriano
wobsoriano15mo ago
hey @kaytitulaer3820, do you have an example of how you converted this code with new functions?
for await (const line of readLines(process.stdout)) {
emit_console_out(line);
}
for await (const line of readLines(process.stdout)) {
emit_console_out(line);
}
I tried this but it exits immediately
this._process = new Deno.Command(Deno.execPath(), {
args: cmd,
stdin: 'piped',
stderr: 'piped',
stdout: 'piped',
})

const child = this._process.spawn();

const stdout = readerFromStreamReader(child.stdout.getReader());
const stderr = readerFromStreamReader(child.stderr.getReader());
for await (const line of readLines(stdout)) {
if (line.trim()) this.emit('data', line);
}

// exits
this._process = new Deno.Command(Deno.execPath(), {
args: cmd,
stdin: 'piped',
stderr: 'piped',
stdout: 'piped',
})

const child = this._process.spawn();

const stdout = readerFromStreamReader(child.stdout.getReader());
const stderr = readerFromStreamReader(child.stderr.getReader());
for await (const line of readLines(stdout)) {
if (line.trim()) this.emit('data', line);
}

// exits