pty icon indicating copy to clipboard operation
pty copied to clipboard

execute only first entered in therminal

Open mykolq opened this issue 10 months ago • 0 comments

`//go:build linux // +build linux

package main

import ( "io" "os" "os/exec" "time"

"github.com/creack/pty"

)

func main() {

cliPath := "/usr/bin/ssh"
sshOpenSession := exec.Command(cliPath, "user@address", "-c", "aes128-cbc", "-o", "StrictHostKeyChecking=no")

ptm, err := pty.Start(sshOpenSession)
if err != nil {
	panic(err)
}
defer func() { _ = ptm.Close() }()
time.Sleep(5 * time.Second)
go func() {
	ptm.Write([]byte("password\n"))
	//time.Sleep(2 * time.Second)
	ptm.Write([]byte("test\n"))
	ptm.Write([]byte("exit\n"))
}()
io.Copy(os.Stdout, ptm)
ptm.Close()

}` i start this code and it seems that code only entered password, but no startig test and exit commands. am i use it wrong?

mykolq avatar Apr 19 '24 17:04 mykolq