Skip to content

Commit

Permalink
Example RedHatOfficial#5: Python interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed Nov 27, 2019
1 parent 33e04cc commit 73e8a10
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions testing/go-expect/05_python.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"log"
"os"
"os/exec"
"time"

expect "github.com/Netflix/go-expect"
)

func main() {
console, err := expect.NewConsole(expect.WithStdout(os.Stdout))
if err != nil {
log.Fatal(err)
}
defer console.Close()

command := exec.Command("python")
command.Stdin = console.Tty()
command.Stdout = console.Tty()
command.Stderr = console.Tty()

err = command.Start()
if err != nil {
log.Fatal(err)
}

time.Sleep(time.Second)
console.ExpectString(">>> ")

console.SendLine("1+2")
console.ExpectString("3")
console.ExpectString(">>> ")

console.SendLine("6*7")
console.ExpectString("42")
console.ExpectString(">>> ")

console.SendLine("quit()")

err = command.Wait()
if err != nil {
log.Fatal(err)
}
}

0 comments on commit 73e8a10

Please sign in to comment.