MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / NewCommand

Function NewCommand

core/utils/terminal/local_cmd.go:28–54  ·  view source on GitHub ↗
(script string)

Source from the content-addressed store, hash-verified

26}
27
28func NewCommand(script string) (*LocalCommand, error) {
29 cmd := exec.Command("bash")
30 if term := os.Getenv("TERM"); term != "" {
31 cmd.Env = append(os.Environ(), "TERM="+term)
32 } else {
33 cmd.Env = append(os.Environ(), "TERM=xterm")
34 }
35 cmd.Env = append(cmd.Env, "INIT_SCRIPT="+script)
36 pty, err := pty.Start(cmd)
37 if err != nil {
38 return nil, errors.Wrapf(err, "failed to start command")
39 }
40 if len(script) != 0 {
41 time.Sleep(100 * time.Millisecond)
42 _, _ = pty.Write([]byte("bash -c \"$INIT_SCRIPT\"\n"))
43 }
44
45 lcmd := &LocalCommand{
46 closeSignal: DefaultCloseSignal,
47 closeTimeout: DefaultCloseTimeout,
48
49 cmd: cmd,
50 pty: pty,
51 }
52
53 return lcmd, nil
54}
55
56func (lcmd *LocalCommand) Read(p []byte) (n int, err error) {
57 return lcmd.pty.Read(p)

Callers

nothing calls this directly

Calls 2

StartMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected