feat: add subprocess.term()
This commit is contained in:
parent
7d441d3bcf
commit
9be51bb18a
1 changed files with 13 additions and 2 deletions
|
@ -51,6 +51,11 @@ pub fn close(self: *Self) tp.result {
|
||||||
if (self.pid) |pid| if (!pid.expired()) try pid.send(.{"stdin_close"});
|
if (self.pid) |pid| if (!pid.expired()) try pid.send(.{"stdin_close"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn term(self: *Self) tp.result {
|
||||||
|
defer self.deinit();
|
||||||
|
if (self.pid) |pid| if (!pid.expired()) try pid.send(.{"term"});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn writer(self: *Self) Writer {
|
pub fn writer(self: *Self) Writer {
|
||||||
return .{ .context = self };
|
return .{ .context = self };
|
||||||
}
|
}
|
||||||
|
@ -201,6 +206,9 @@ const Proc = struct {
|
||||||
fd.close();
|
fd.close();
|
||||||
self.child.stderr = null;
|
self.child.stderr = null;
|
||||||
}
|
}
|
||||||
|
} else if (try m.match(.{"term"})) {
|
||||||
|
const term_ = self.child.kill() catch |e| return tp.exit_error(e);
|
||||||
|
return self.handle_term(term_);
|
||||||
} else if (try m.match(.{ "fd", tp.any, "read_error", tp.extract(&err), tp.extract(&err_msg) })) {
|
} else if (try m.match(.{ "fd", tp.any, "read_error", tp.extract(&err), tp.extract(&err_msg) })) {
|
||||||
return tp.exit(err_msg);
|
return tp.exit(err_msg);
|
||||||
}
|
}
|
||||||
|
@ -239,8 +247,11 @@ const Proc = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_terminate(self: *Proc) tp.result {
|
fn handle_terminate(self: *Proc) tp.result {
|
||||||
const term = self.child.wait() catch |e| return tp.exit_error(e);
|
return self.handle_term(self.child.wait() catch |e| return tp.exit_error(e));
|
||||||
(switch (term) {
|
}
|
||||||
|
|
||||||
|
fn handle_term(self: *Proc, term_: std.ChildProcess.Term) tp.result {
|
||||||
|
(switch (term_) {
|
||||||
.Exited => |val| self.parent.send(.{ self.tag, "term", "exited", val }),
|
.Exited => |val| self.parent.send(.{ self.tag, "term", "exited", val }),
|
||||||
.Signal => |val| self.parent.send(.{ self.tag, "term", "signal", val }),
|
.Signal => |val| self.parent.send(.{ self.tag, "term", "signal", val }),
|
||||||
.Stopped => |val| self.parent.send(.{ self.tag, "term", "stop", val }),
|
.Stopped => |val| self.parent.send(.{ self.tag, "term", "stop", val }),
|
||||||
|
|
Loading…
Add table
Reference in a new issue