我试图通过golang使用awk,并且我编写了如下程序,但它没有显示输出,也没有显示任何错误。
package main
import ("os/exec"
"fmt"
)
func main() {
app := "tail"
arg0 := "-n"
arg1 := "1"
arg2 := "/var/log/apache2/access.log"
app1 := "awk"
arg5 := "{print $1}"
//arg6 := ">>"
//arg7 := "mem_usage.csv"
cmd := exec.Command(app, arg0, arg1, arg2)
stdout, err := cmd.StdoutPipe()
//out, err := cmd.Output()
if err != nil {
fmt.Println(err.Error())
return
}
cmd1 := exec.Command(app1, arg5)//, arg6, arg7)
cmd1.Stdin = stdout
out1,err1 := cmd1.Output()
if err1 != nil {
fmt.Println(err1.Error())
return
}
fmt.Println(string(out1))
//fmt.Println(string(out))
}