Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Go channels exitation

I'm creating a simple bash interaction with net.Conn. I can't figure out one thing: I want to be able to type some string like "abrakadabra" from inside the created bash connection and that it will cause bash connection to exit itself (to return to normal business in my code).

Question: How do I take a string typed to an active bash connection and use it in an if condition later in my code? / any other solution to this?

This is the code:

type Progress struct {
    bytes uint64
}

func interact(c net.Conn) {
    wat := make(chan Progress)
    // Read from Reader and write to Writer until EOF()
    copy := func(r io.ReadCloser, w io.WriteCloser) {
        defer func() {
            r.Close()
            w.Close()
        }()
        n, err := io.Copy(w, r)
        if err != nil {
            log.Printf("[%s]: ERROR: %s\n", c.RemoteAddr(), err)
        }
        wat <- Progress{bytes: uint64(n)}
    }

    go copy(c, os.Stdout)
    go copy(os.Stdin, c)

Comments