跳到主要内容

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

浏览文件

command.go

54 行 · 1.0 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package executil
5
6import (
7 "bytes"
8 "context"
9 "fmt"
10 "os/exec"
11
12 "github.com/lima-vm/lima/v2/pkg/strutil"
13)
14
15type options struct {
16 ctx context.Context
17}
18
19type Opt func(*options) error
20
21// WithContext runs the command with CommandContext.
22func WithContext(ctx context.Context) Opt {
23 return func(o *options) error {
24 o.ctx = ctx
25 return nil
26 }
27}
28
29func RunUTF16leCommand(args []string, opts ...Opt) (string, error) {
30 var o options
31 for _, f := range opts {
32 if err := f(&o); err != nil {
33 return "", err
34 }
35 }
36
37 var cmd *exec.Cmd
38 ctx := o.ctx
39 if ctx == nil {
40 ctx = context.Background()
41 }
42 cmd = exec.CommandContext(ctx, args[0], args[1:]...)
43
44 outString := ""
45 out, err := cmd.CombinedOutput()
46 if out != nil {
47 s, err := strutil.FromUTF16leToString(bytes.NewReader(out))
48 if err != nil {
49 return "", fmt.Errorf("failed to convert output from UTF16 when running command %v, err: %w", args, err)
50 }
51 outString = s
52 }
53 return outString, err
54}