<p>Hi there. I'm not the most hot devops/bash-y person in the world. Running <code>go run *.go</code> spits out the log of what happens in my app. If I try to make a shell sccript to loop through a bunch of folders and run <code>go run *.go</code> in each one, it stops at the first one, as expected. How can I tell bash to continue, or open a new process, or whatever? </p>
<p>Thanks : )</p>
<hr/>**评论:**<br/><br/>wheey: <pre><p>I think this should be posted in <a href="/r/bash" rel="nofollow">/r/bash</a>, but anyhow I am not sure what you expect to happen here after execution:</p>
<ul>
<li><p>Execute all and exit bash script</p></li>
<li><p>Execute all and wait until Ctrl+C is pressed which would kill all executed and exit the bash script</p></li>
</ul>
<p>If you need just execute all and then exit bash script I would go this route:</p>
<p>go run *.go >> stdout_log_filename 2>> stderr_log_filename &</p>
<p>PID1=$!</p>
<p>go run *.go >> stdout_log_filename 2>> stderr_log_filename &</p>
<p>PID2=$!</p>
<p>This will give you two separate log files for each "instance", one which will have stdout (useful if your go uses fmt.Println or similar which outputs to console), and stderr which will be written only on standard error.</p>
<p>Each "instance" will have own PID which you need to remember (write it to file then later read from file and check if it's running), or using ps command. </p>
<p>Please note that you will need to make "start|stop" script.</p></pre>diabetesjones: <pre><p>Exactly what I wanted. Thanks very much for your help!</p></pre>ashfame: <pre><p>Think you can just do “go run *.go &”</p>
<p>Why do you need to do this though? Curious as to what use case can possible require this.</p></pre>diabetesjones: <pre><p>I'm just playing around with how Go and bash work. Starting a bunch of different services at once before moving to docker/docker compose to bring them up.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传