summaryrefslogtreecommitdiff
path: root/cli/js/ops/process.ts
blob: 86a0c9a712bc1ad0ec810d2ed5a7f272a54e139c (plain)
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
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

import { sendSync, sendAsync } from "./dispatch_json.ts";
import { assert } from "../util.ts";

export function kill(pid: number, signo: number): void {
  sendSync("op_kill", { pid, signo });
}

interface RunStatusResponse {
  gotSignal: boolean;
  exitCode: number;
  exitSignal: number;
}

export function runStatus(rid: number): Promise<RunStatusResponse> {
  return sendAsync("op_run_status", { rid });
}

interface RunRequest {
  cmd: string[];
  cwd?: string;
  env?: Array<[string, string]>;
  stdin: string;
  stdout: string;
  stderr: string;
  stdinRid: number;
  stdoutRid: number;
  stderrRid: number;
}

interface RunResponse {
  rid: number;
  pid: number;
  stdinRid: number | null;
  stdoutRid: number | null;
  stderrRid: number | null;
}

export function run(request: RunRequest): RunResponse {
  assert(request.cmd.length > 0);
  return sendSync("op_run", request);
}