feat: 新增 proc.list/user.list/pkg.list 命令
proc.list 列出所有进程(ps aux/tasklist) user.list 列出系统用户(getent passwd/net user) pkg.list 列出已安装软件包(dpkg/rpm/apk/brew/winget)
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package executor
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// runProcList implements `kopsc proc list`: list all processes.
|
||||
func runProcList(ctx context.Context, req BuiltinRequest) error {
|
||||
switch runtime.GOOS {
|
||||
case "linux", "darwin":
|
||||
cmd := exec.CommandContext(ctx, "ps", "aux")
|
||||
cmd.Stdout = req.Stdout
|
||||
cmd.Stderr = req.Stderr
|
||||
return cmd.Run()
|
||||
case "windows":
|
||||
cmd := exec.CommandContext(ctx, "tasklist")
|
||||
cmd.Stdout = req.Stdout
|
||||
cmd.Stderr = req.Stderr
|
||||
return cmd.Run()
|
||||
default:
|
||||
return fmt.Errorf("不支持的操作系统: %s", runtime.GOOS)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user