1. The simple
If you are using Linux write log from Python to stdout and use pipe.
sourse.py | target (written in go)
package main
import (
"bufio"
"fmt"
"os"
)
/*
Three ways of taking input
1. fmt.Scanln(&input)
2. reader.ReadString()
3. scanner.Scan()
Here we recommend using bufio.NewScanner
*/
func main() {
// To create dynamic array
arr := make([]string, 0)
scanner := bufio.NewScanner(os.Stdin)
for {
fmt.Print("Enter Text: ")
// Scans a line from Stdin(Console)
scanner.Scan()
// Holds the string that scanned
text := scanner.Text()
if len(text) != 0 {
fmt.Println(text)
arr = append(arr, text)
} else {
break
}
}
// Use collected inputs
fmt.Println(arr)
}
Usage:
echo "what a wanderful world" |./go-bin
Also read this Python redirect to StdOut
2. The right.
It may be better for a long running process to use Named pipe.
Which is a linux file (FIFO) GNU pipe.
Python write to this file and Golang read it
FIFO example in go
3. The probably oveverkill.
Write a Golang web server and call the server endpoint from python.
If you can change the Python source.
Security also should get more attention with this sulotion.