My (Go) program feeds into `gofmt`s stdin --- how should it signal end-of-data?

blov · · 358 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m wondering about the idiomatic cross-platform way, and the <em>general</em> approach. Is it entirely program-specific, is there a convention, or is there a simple standard signaling? In the terminal of course you easily signal EOF (or EOD?) via Ctrl+D which the keyboard/OS/terminal-emulator translates into a commonly accepted signal, but maybe outside a &#34;user in front of terminal typing std-input&#34; context there&#39;s a preferred different method, some SIGFOO process signaling or some such? If not, um, if you have it handy what&#39;s the in-string backslashed escape-sequence to send at the end to say &#34;process this input now, nothing more coming in&#34;? =)</p> <p><strong>Update</strong> thanks guys, of course that&#39;d be it. How did that not even occur to me! That&#39;s what I get for asking before trying for a change ;D cheers</p> <hr/>**评论:**<br/><br/>hlidotbe: <pre><p>I may be wrong but doesn&#39;t closing the io writer signals EOF?</p></pre>FUZxxl: <pre><p>Close the file descriptor. That signalizes EOF on the other end of the pipe.</p></pre>zeiko_is_back: <pre><p>Close the io.ReadWriter</p> <p><a href="https://golang.org/pkg/os/exec/#Cmd.StdinPipe">https://golang.org/pkg/os/exec/#Cmd.StdinPipe</a></p></pre>lstokeworth: <pre><p>The <a href="https://godoc.org/go/format#Source" rel="nofollow">format.Source</a> function is an alternative to running gofmt to format code.</p></pre>meta_leap: <pre><p>I wondered why <code>gofmt</code> <a href="https://golang.org/src/cmd/gofmt/" rel="nofollow">doesn&#39;t</a> even import it. But looking at both their sources, <code>gofmt</code> seems to do a whole lot more in terms of LoC at least, guess it handles more edge cases like partial inputs (extracted lines, incomplete blocks etc etc), plus of course the rewrite rules and the simplifier.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

358 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传