以下工作并打印命令输出:
out, err := exec.Command("ps", "cax").Output()
但是此操作失败(退出状态为1):
out, err := exec.Command("ps", "cax | grep myapp").Output()
有什么建议?
您可以这样做:
out, err := exec.Command("bash", "-c", "ps cax | grep myapp").Output()