Skip to content

🐚 Execute and interact with any command line program using Go channels.

License

Notifications You must be signed in to change notification settings

integrii/interactive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

interactive 🐚

Interactive is a package for easily executing and interacting with CLI commands using channels. Uses a PTY and simple channels for inputting lines of strings and reading lines of strings. You can always go direct to the running process and write bytes, though, too. A cool example of this in use is my headlessChrome package which starts headless chrome with --repl (a command line javascript console interface) for very, very realistic website automation.

Automate any command line task with a go program! Special thanks to github.com/kr/pty

Get It

go get -u github.com/integrii/interactive

Read the Godoc

https://godoc.org/github.com/integrii/interactive

Example

func main() {
  // Start the command "bc" (a CLI calculator)
  bc, err := interactive.NewSession("bc", []string{})
  if err != nil {
    panic(err)
  }

  // start a concurrent output reader from the output channel of our command
  go outputPrinter(bc.Output)

  // write 1 + 1 to the bc prompt
  bc.Write(`1 + 1`)

  // wait one second for the output to come and be displayed
  time.Sleep(time.Second)

}

func outputPrinter(c chan string) {
  for s := range c {
    fmt.Println(s)
  }
}

This will print to the console the following:

bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
1 + 1
2

You can run and control nearly anything you could from your console this way.

About

🐚 Execute and interact with any command line program using Go channels.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages