Skip to content

Commit 8e0e14e

Browse files
authored
Update ptycmd.go
1 parent a8b6468 commit 8e0e14e

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Orca_Master/cli/controller/ptycmd.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"Orca_Master/cli/common"
66
"Orca_Master/define/colorcode"
77
"Orca_Master/define/retcode"
8+
"bufio"
89
"bytes"
910
"fmt"
1011
"github.com/desertbit/grumble"
1112
"os"
1213
"os/signal"
14+
"runtime"
1315
"time"
1416
)
1517

@@ -42,14 +44,20 @@ var ptyCmd = &grumble.Command{
4244
case <-time.After(10 * time.Second):
4345
return fmt.Errorf("request timed out")
4446
}
45-
46-
var data []byte
4747
for {
48-
input := [512]byte{}
49-
os.Stdin.Read(input[:])
50-
data = bytes.Replace(input[:], []byte{13, 10}, []byte{10, 00}, -1) // 将windows\r\n替换为linux的\n
51-
data = bytes.Trim(data, "\x00")
52-
cmd := string(data)
48+
var cmd string
49+
if runtime.GOOS == "windows" {
50+
input := [512]byte{}
51+
os.Stdin.Read(input[:])
52+
data := bytes.Replace(input[:], []byte{13, 10}, []byte{10, 00}, -1) // 将windows\r\n替换为linux的\n
53+
data = bytes.Trim(data, "\x00")
54+
cmd = string(data)
55+
} else {
56+
reader := bufio.NewReader(os.Stdin)
57+
data, _ := reader.ReadBytes('\n')
58+
cmd = string(data)
59+
}
60+
5361
retData = ptyopt.SendCommandToPty(SelectClientId, cmd)
5462
if retData.Code != retcode.SUCCESS {
5563
colorcode.PrintMessage(colorcode.SIGN_FAIL, "command send failed")

0 commit comments

Comments
 (0)