1
使用exec.Command执行带管道的命令
source link: https://zhangyiming748.github.io/post/golang_use_cmd/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
使用exec.Command执行带管道的命令
2023-11-07 Golang
使用 sh -c ""命令exec.Command("bash", "-c", "ps aux|grep go")
这是推荐的做法。
如果输出不是很多,推荐使用github.com/go-cmd/cmd库来执行系统命令,如:
import "github.com/go-cmd/cmd"
c := cmd.NewCmd("bash", "-c", "ps aux|grep go")
<-c.Start()
fmt.Println(c.Status().Stdout)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK