<p>I have a simple program that reads an input by command line. How can i execute this with exec.Command and pass the required data only using the bufio scanner? </p>
<p>This is the simple script that i give to the exec.Command function</p>
<pre><code>reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter text: ")
text, _ := reader.ReadString('\n')
fmt.Println(text)
</code></pre>
<hr/>**评论:**<br/><br/>desmond_tutu: <pre><p><a href="https://golang.org/pkg/os/exec/#example_Cmd_StdinPipe" rel="nofollow">https://golang.org/pkg/os/exec/#example_Cmd_StdinPipe</a> - is that what you're looking for?</p></pre>Asoseil: <pre><p>perfect, but now how can i intercept the reader from the launched program? i would like insert the text from command line and pass it to my script.</p></pre>SaturnsVoid: <pre><p>Maybe this could help? <a href="https://github.com/SaturnsVoid/GoBot2/blob/master/components/RemoteCMD.go" rel="nofollow">https://github.com/SaturnsVoid/GoBot2/blob/master/components/RemoteCMD.go</a></p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传