I have following task: need connecting Go pipe with Python. I understand how run pythonic process under Go:
var compiler string = "python"
var path string = "...here script path"
pyExec := exec.Command(compiler, path)
pyExecIn, _ := pyExec.StdinPipe()
pyExecOut, _ := pyExec.StdoutPipe()
pyExec.Start()
// acitions
pyExec.Wait()
I can write data in stdin but I read it only after terminating script. For get data inside process I decide use pipe, but I only can write message into pythonic script. When Go trying read data from python process is blocked. Answer me please, this is trouble with implementation or Goland pipes and pythonic pipes not compatible? Exist another way connection both process (except socket and so on)
Go:
var compiler string = "python"
var path string = "...here script path"
pyExec := exec.Command(compiler, path)
pyExecIn, _ := pyExec.StdinPipe()
pyExecOut, _ := pyExec.StdoutPipe()
pipeReader, pipeWriter := io.Pipe()
pyExec.Stdin = pipeReader
pyExec.Stdout = pipeWriter
pyExec.Start()
pipeWriter.Write(message)
var received_data = make([]byte, 1024)
data, _ := pipeReader.Read(received_data)
pyExecIn.Close()
pyExecOut.Close()
pyExec.Wait()
Python:
r, w = os.pipe()
r = os.fdopen(r, 'r')
raw_responce = r.read(1024)
# actions
w = os.fdopen(w, 'w')
w.write(data)
Thanks