deno.land / x / deno@v1.28.2 / runtime / js / 40_process.js

نووسراو ببینە
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license."use strict";
((window) => { const core = window.Deno.core; const ops = core.ops; const { FsFile } = window.__bootstrap.files; const { readAll } = window.__bootstrap.io; const { pathFromURL } = window.__bootstrap.util; const { assert } = window.__bootstrap.infra; const { ArrayPrototypeMap, ArrayPrototypeSlice, TypeError, ObjectEntries, String, } = window.__bootstrap.primordials;
function opKill(pid, signo, apiName) { ops.op_kill(pid, signo, apiName); }
function kill(pid, signo = "SIGTERM") { opKill(pid, signo, "Deno.kill()"); }
function opRunStatus(rid) { return core.opAsync("op_run_status", rid); }
function opRun(request) { assert(request.cmd.length > 0); return ops.op_run(request); }
async function runStatus(rid) { const res = await opRunStatus(rid);
if (res.gotSignal) { const signal = res.exitSignal; return { success: false, code: 128 + signal, signal }; } else if (res.exitCode != 0) { return { success: false, code: res.exitCode }; } else { return { success: true, code: 0 }; } }
class Process { constructor(res) { this.rid = res.rid; this.pid = res.pid;
if (res.stdinRid && res.stdinRid > 0) { this.stdin = new FsFile(res.stdinRid); }
if (res.stdoutRid && res.stdoutRid > 0) { this.stdout = new FsFile(res.stdoutRid); }
if (res.stderrRid && res.stderrRid > 0) { this.stderr = new FsFile(res.stderrRid); } }
status() { return runStatus(this.rid); }
async output() { if (!this.stdout) { throw new TypeError("stdout was not piped"); } try { return await readAll(this.stdout); } finally { this.stdout.close(); } }
async stderrOutput() { if (!this.stderr) { throw new TypeError("stderr was not piped"); } try { return await readAll(this.stderr); } finally { this.stderr.close(); } }
close() { core.close(this.rid); }
kill(signo = "SIGTERM") { opKill(this.pid, signo, "Deno.Process.kill()"); } }
function run({ cmd, cwd = undefined, clearEnv = false, env = {}, gid = undefined, uid = undefined, stdout = "inherit", stderr = "inherit", stdin = "inherit", }) { if (cmd[0] != null) { cmd = [pathFromURL(cmd[0]), ...ArrayPrototypeSlice(cmd, 1)]; } const res = opRun({ cmd: ArrayPrototypeMap(cmd, String), cwd, clearEnv, env: ObjectEntries(env), gid, uid, stdin, stdout, stderr, }); return new Process(res); }
window.__bootstrap.process = { run, Process, kill, };})(this);
deno

Version Info

Tagged at
a year ago