<p>Hello, I am trying to run a linux command via Go. Here is what I have, for some reason it is not working... Any advice?</p>
<p>exec.Command("echo", "'hello! your email is: '" + email + " | mail -s 'Activate Book Hook Account' " + email)</p>
<p>Thanks!</p>
<hr/>**评论:**<br/><br/>_dirtyburger: <pre><p>You can do something like:</p>
<pre><code>email := "fake@fake.com"
line := "echo hello your email is: " + email + " | cut -c 1-8"
out, err := exec.Command("bash", "-c", line).Output()
if err != nil {
log.Fatalf("Command line error: %v", err)
}
fmt.Printf("Command line output: %v", string(out))
</code></pre>
<p>Use the bash command and give the -c option to read commands from the string which contains the command line. Im not sure what your command line is trying to do though. </p></pre>justinisrael: <pre><p>The command is trying to dynamically format an email to a particular user by piping it </p></pre>wwader: <pre><p>Hi, that only defines a command, you have to run it also using .Output(), .Run() or .Start() etc</p></pre>emersion_fr: <pre><p>Be very careful when doing things like this. It's really super-easy to insert <code>;rm -rf *;</code> in the command.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传