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 關注
- 87 瀏覽
添加回答
舉報