Here is the solution which I found here (thank you Malcolm)
func Readln(r *bufio.Reader) (string, error) {
var (
isPrefix = true
err error
line, ln []byte
)
for isPrefix && err == nil {
line, isPrefix, err = r.ReadLine()
ln = append(ln, line...)
}
return string(ln), err
}
func handle(s string) {
//Do something with your string
}
func main() {
c := exec.Command("sh", "./tmuxpipe.sh")
err := c.Run()
if err != nil {
log.Fatal(err)
}
f, err := os.Open("/tmp/tmuxpipe")
if err != nil {
fmt.Printf("error opening file: %v
", err)
os.Exit(1)
}
r := bufio.NewReader(f)
s, e := Readln(r)
for e == nil {
handle(s)
log.Println(s)
s, e = Readln(r)
}
}
here is the tmuxpipe.sh:
mkfifo /tmp/tmuxpipe
tmux pipe-pane -o -t tmuxSession 'cat >> /tmp/tmuxpipe'
The reason I did not just use exec.Command()
there, is because for some reason beyond my comprehension this:
c := exec.Command("tmux", "pipe-pane", "-o", "-t", "tmuxSession", 'cat >> /tmp/tmuxpipe'")
err := c.Run()
handleError(err)
did not work (for me).
There was no error occuring, but the output of the tmux session wasn't displayd either.
I hope this helps anybody