I have a program which calls a script that outputs progress information in line-break separated output with a prefix in JSON on file descriptor number 3:
use std::process::Command;
fn main() {
let out = Command::new("bash")
.arg("test.sh")
.output()
.expect("failed to execute install command");
}
#!/bin/bash
while sleep 1s; do # random progress emulator
echo "@progress {\"key\": \"value\"}" >&3
done
Nothing I've found provided any good example of how to actually to this.
The JavaScript equivalent would be:
#!/usr/bin/env node
const cp = require('child_process')
const p = cp.spawn('bash', [ 'test.sh' ], { stdio: [ 'pipe', 'inherit', 'inherit', /* 3 */ 'pipe' ] })
const readline = require('readline')
const rl = readline.createInterface({
input: p.stdio[3]
})
rl.on('line', (line) => console.log(JSON.parse(line.substr(10))))