Created
October 17, 2018 11:17
-
-
Save smallnest/c3b7f6f0e814e1825be96789ea958215 to your computer and use it in GitHub Desktop.
在exec使用linux管道
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| out, err := exec.Command("bash", "-c", "ps cax | grep myapp").Output() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you type the command at the shell, the shell takes ./source_dir/* and replaces it with a list of all of the files that match, one per argument. The mv command sees a list of filenames, not a wildcard.
What you need to do is either do the same thing yourself (using filepath.Glob which returns a []string of matching files), or to invoke the shell so that it can do the work (using exec.Command("/bin/sh", "-c", "mv ./source_dir/* ./dest_dir")).
https://stackoverflow.com/questions/41037870/go-exec-command-run-command-which-contains-pipe
https://stackoverflow.com/questions/31467153/golang-failed-exec-command-that-works-in-terminal