-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathcmd.ts
More file actions
49 lines (43 loc) · 975 Bytes
/
cmd.ts
File metadata and controls
49 lines (43 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* cmd.ts
*
* Copyright (C) 2020-2022 Posit Software, PBC
*
*/
import { debug, error, info } from "../../../src/deno_ral/log.ts";
export interface CmdResult {
status: Deno.CommandStatus;
stdout: string;
stderr: string;
}
export async function runCmd(
runCmd: string,
args: string[],
): Promise<CmdResult> {
// const cmd: string[] = [];
// cmd.push(runCmd);
// cmd.push(...args);
info([runCmd, ...args]);
info(`Starting ${runCmd}`);
const cmd = new Deno.Command(runCmd, {
args,
stdout: "piped",
stderr: "piped",
});
const output = await cmd.output();
const stdout = new TextDecoder().decode(output.stdout);
const stderr = new TextDecoder().decode(output.stderr);
info(`Finished ${runCmd}`);
debug(stdout);
const code = output.code;
info(`Status ${code}`);
if (code !== 0) {
error(stderr);
throw Error(`Command ${[runCmd, ...args]} failed.`);
}
return {
status: output,
stdout,
stderr,
};
}