跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

process_windows.go

43 行 · 954 B历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package windows
5
6import (
7 "context"
8 "encoding/json"
9 "fmt"
10 "os/exec"
11)
12
13type CommandLineJSON []struct {
14 CommandLine string
15}
16
17// GetProcessCommandLine returns a slice of string containing all commandlines for a given process name.
18func GetProcessCommandLine(ctx context.Context, name string) ([]string, error) {
19 out, err := exec.CommandContext(ctx,
20 "powershell.exe",
21 "-nologo",
22 "-noprofile",
23 fmt.Sprintf(
24 `Get-CimInstance Win32_Process -Filter "name = '%s'" | Select CommandLine | ConvertTo-Json`,
25 name,
26 ),
27 ).CombinedOutput()
28 if err != nil {
29 return nil, err
30 }
31
32 var outJSON CommandLineJSON
33 if err = json.Unmarshal(out, &outJSON); err != nil {
34 return nil, fmt.Errorf("failed to unmarshal %#q as %T: %w", out, outJSON, err)
35 }
36
37 var ret []string
38 for _, s := range outJSON {
39 ret = append(ret, s.CommandLine)
40 }
41
42 return ret, nil
43}