feat: 新增 proc wait,等待进程退出
- 每秒检查一次目标进程,存在则继续等待,直到消失为止 - 关键字在进程名与命令行中匹配(忽略大小写),多个关键字为逻辑与; --pid 可直接指定进程 ID(逗号分隔可多个) - 默认不超时,--timeout 限时(退出码 2 并列出残留 PID),--once 只检查一次 - 三平台实现:Linux 读 /proc(回退 ps)、macOS 用 ps、Windows 用 tasklist - ExitError 改为优先展示具体原因,不再只显示「命令以状态码 N 退出」 - 文档:README.proc.md 新增完整小节,主 README 补充示例与速查
This commit is contained in:
@@ -196,9 +196,22 @@ type ExitError struct {
|
||||
}
|
||||
|
||||
func (e *ExitError) Error() string {
|
||||
// When the error carries its own explanation (for example a timeout that
|
||||
// lists what is still running), show it instead of the bare status code.
|
||||
if e.Err != nil {
|
||||
if msg := e.Err.Error(); msg != "" && !isExitStatus(msg) {
|
||||
return msg
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("命令以状态码 %d 退出", e.Code)
|
||||
}
|
||||
|
||||
// isExitStatus reports whether msg is just an os/exec exit status, which adds
|
||||
// nothing to kopsc's own wording.
|
||||
func isExitStatus(msg string) bool {
|
||||
return strings.HasPrefix(msg, "exit status ") || strings.HasPrefix(msg, "signal: ")
|
||||
}
|
||||
|
||||
func (e *ExitError) Unwrap() error { return e.Err }
|
||||
|
||||
// ExitCode maps an error to the process exit code kopsc should return.
|
||||
|
||||
Reference in New Issue
Block a user