Is it possible to redirect stdin/stdout with go:generate

huangapple go评论146阅读模式
英文:

Is it possible to redirect stdin/stdout with go:generate

问题

我有一个工具,它作为一个管道,从标准输入读取数据,并将Go源代码写入标准输出。

是否可以设置输入/输出重定向,并在go:generate中使用这样的工具?类似于:

//go:generate tool < file.txt > file.go
英文:

I have a tool that acts as a pipe, it reads data from stdin and writes go source code to stdout.

Is it possible to setup input/output redirection and use such tool with go:generate? Something like:

//go:generate tool &lt; file.txt &gt; file.go

答案1

得分: 21

我找到了如何做到这一点:

//go:generate sh -c "tool < file.txt > file.go"
英文:

I figured out how to do it:

//go:generate sh -c &quot;tool &lt; file.txt &gt; file.go&quot;

huangapple
  • 本文由 发表于 2015年8月21日 23:41:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/32144379.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定