gpt4 book ai didi

go - 如何通过标准输入将 []byte 传递给外部 exiftool?

转载 作者:数据小太阳 更新时间:2023-10-29 03:06:56 24 4
gpt4 key购买 nike

我正在尝试在 golang 中做 bash 等价物:

cat image.jpg | exiftool -author=some_auth - > updated_image.jpg

exiftool '-' 选项使它从 stdin 读取,但是说我将图像存储在一个变量中,例如 var img []bytes//在 golang 中

我希望 stdin 包含来自 img 的字节和对 exiftool 的系统调用以从 stdin 读取这些字节,将结果 (stdout) 保存在另一个 []byte - 我是 golang 的新手,我该如何处理这个?

我不想保存到磁盘上的临时文件。

谢谢

最佳答案

有点像

out, err := os.Create("updated_image.jpg")
if err != nil {
log.Fatal(err)
}
cmd := exec.Command("exiftool", "-author=some_auth", "-")
cmd.Stdout = out
cmd.Stdin = bytes.NewReader(img)
err = cmd.Run()
if err != nil {
log.Fatal(err)
}
out.Close()

应该可以。

请注意,我还没有测试代码。

关于go - 如何通过标准输入将 []byte 传递给外部 exiftool?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31108091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com