Search code examples
gopipeexec

Go exec.Command() - run command which contains pipe


The following works and prints the command output:

out, err := exec.Command("ps", "cax").Output()

but this one fails (with exit status 1):

out, err := exec.Command("ps", "cax | grep myapp").Output()

Any suggestions?


Solution

  • You could do:

    out, err := exec.Command("bash", "-c", "ps cax | grep myapp").Output()