1 回答
TA贡献1891条经验 获得超3个赞
1. 简单的
如果您使用的是 Linux,则将日志从 Python 写入标准输出并使用管道。来源.py | 目标(用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)
}
用法:
echo "what a wanderful world" |./go-bin
另请阅读此Python redirect to StdOut
2.权利。
对于长时间运行的进程,使用命名管道可能更好。这是一个 linux 文件 (FIFO) GNU pipe。
Python 写入此文件,Golang 读取 go 中的 FIFO 示例
3. 可能矫枉过正。
编写 Golang Web 服务器并从 python 调用服务器端点。
如果可以更改 Python 源代码。
此解决方案还应更加关注安全性。
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报
