how to handle process output in go using named pipe -


i trying set pipe running process in tmux,
in order handle output line line.

i have had @ this guide pipe output of tmux session stdout
, this article (named) pipes in go.

i have been trying around quite while now,
still didn't noteworthy results.

i appreciate thoughts on how set pipe up,
ideally in way can range on linewise.

thanks lot

here solution found here (thank malcolm)

func readln(r *bufio.reader) (string, error) {     var (         isprefix = true         err      error         line, ln []byte     )     isprefix && err == nil {         line, isprefix, err = r.readline()         ln = append(ln, line...)     }     return string(ln), err }  func handle(s string) {     //do 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\n", err)         os.exit(1)     }     r := bufio.newreader(f)     s, e := readln(r)     e == nil {         handle(s)         log.println(s)         s, e = readln(r)     } } 

here tmuxpipe.sh:

mkfifo /tmp/tmuxpipe tmux pipe-pane -o -t tmuxsession 'cat >> /tmp/tmuxpipe' 

the reason did not use exec.command() there, because reason beyond 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 no error occuring, output of tmux session wasn't displayd either.

i hope helps anybody


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -