<p>I'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 "user in front of terminal typing std-input" context there's a preferred different method, some SIGFOO process signaling or some such? If not, um, if you have it handy what's the in-string backslashed escape-sequence to send at the end to say "process this input now, nothing more coming in"? =)</p>
<p><strong>Update</strong> thanks guys, of course that'd be it. How did that not even occur to me! That'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'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'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>
![](https://static.golangjob.cn/static/img/banner.png)