Skip to content

Instantly share code, notes, and snippets.

@jcc10
Last active December 23, 2020 06:03
Show Gist options
  • Save jcc10/8e22746293b594fe4fb43ef4f4f5ff88 to your computer and use it in GitHub Desktop.
Save jcc10/8e22746293b594fe4fb43ef4f4f5ff88 to your computer and use it in GitHub Desktop.
Deno subprossess live monitoring.

This is to demonstrate that you can monitor programs that are currently running (as opposed to only once the program has exited.

Generator generates a specified number of Alpha and Beta line sets.

Monitor passes specified number of lines in and looks for Al (Alpha) and when it finds it, it logs to console.

import { delay } from "https://deno.land/std@0.82.0/async/delay.ts";
import { parse } from "https://deno.land/std@0.82.0/flags/mod.ts";
const parsed = parse(Deno.args);
for(let x = 0; x < parsed._[0]; x++){
console.log("Alpha");
await delay(250);
console.log("Beta");
await delay(250);
}
import { TextProtoReader } from "https://deno.land/std@0.82.0/textproto/mod.ts";
import { BufReader } from "https://deno.land/std@0.82.0/io/bufio.ts";
import { parse } from "https://deno.land/std@0.82.0/flags/mod.ts";
const parsed = parse(Deno.args);
const p = Deno.run({
cmd: [
"deno",
"run",
"https://gist.githubusercontent.com/jcc10/8e22746293b594fe4fb43ef4f4f5ff88/raw/d01e5d75b5ea6baf60a0681259e72967cbe84b32/generator.ts",
`${parsed._[0]}`
],
stdout: "piped",
stderr: "piped",
});
const reader = new TextProtoReader(BufReader.create(p.stdout));
let count = 0;
console.log("Started");
while(true){
const line = await reader.readLine();
if(line === null) break;
if(line?.includes("Al")){
count++;
console.log(`Got ${count}...`)
}
}
console.log("Ended")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment