You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
starainrt/starshell_test.go

61 lines
1.1 KiB
Go

package starainrt
import (
"fmt"
"testing"
"time"
)
func Test_Starshell(t *testing.T) {
star, err := NewStarShell("cmd.exe")
if err != nil {
fmt.Println(err)
return
}
go func() {
time.Sleep(time.Second * 2)
star.WriteCmd("chcp 65001")
time.Sleep(time.Second * 2)
star.WriteCmd("ping baidu.com -n 10")
time.Sleep(time.Second * 12)
star.WriteCmd("exit")
}()
for star.IsRunning() {
time.Sleep(time.Millisecond * 100)
str, err := star.GetResult()
if err != nil {
fmt.Println("error:", err)
}
fmt.Print(str)
}
fmt.Println(star.ExitCode())
}
func Test_Starbash(t *testing.T) {
star, err := NewStarShell("bash", "-c", "ping baidu.com -c 10")
err = star.Start()
if err != nil {
fmt.Println(err)
return
}
/*
go func() {
time.Sleep(time.Second * 2)
star.WriteCmd("chcp 65001")
time.Sleep(time.Second * 2)
star.WriteCmd("ping baidu.com -n 10")
time.Sleep(time.Second * 12)
star.WriteCmd("exit")
}()
*/
for star.IsRunning() {
time.Sleep(time.Millisecond * 100)
str, err := star.GetResult()
if err != nil {
fmt.Println("error:", err)
}
fmt.Print(str)
}
fmt.Println(star.ExitCode())
}