summaryrefslogtreecommitdiff
path: root/js/process.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/process.ts')
-rw-r--r--js/process.ts21
1 files changed, 19 insertions, 2 deletions
diff --git a/js/process.ts b/js/process.ts
index 0a1393ed0..50df88268 100644
--- a/js/process.ts
+++ b/js/process.ts
@@ -2,9 +2,11 @@
import * as dispatch from "./dispatch";
import * as flatbuffers from "./flatbuffers";
import * as msg from "gen/msg_generated";
-import { assert, unreachable } from "./util";
-import { close, File } from "./files";
+
+import { File, close } from "./files";
import { ReadCloser, WriteCloser } from "./io";
+import { readAll } from "./buffer";
+import { assert, unreachable } from "./util";
/** How to handle subsubprocess stdio.
*
@@ -59,6 +61,21 @@ export class Process {
return await runStatus(this.rid);
}
+ /** Buffer the stdout and return it as Uint8Array after EOF.
+ * You must have set stdout to "piped" in when creating the process.
+ * This calls close() on stdout after its done.
+ */
+ async output(): Promise<Uint8Array> {
+ if (!this.stdout) {
+ throw new Error("Process.output: stdout is undefined");
+ }
+ try {
+ return await readAll(this.stdout);
+ } finally {
+ this.stdout.close();
+ }
+ }
+
close(): void {
close(this.rid);
}