2016-04-24 71 views

回答

1

因为你的命令涉及的管道,你可以把它作为一个命令字符串来砸的,而不是直接执行它。像这样的东西应该工作。

package main 

import (
    "fmt" 
    "os/exec" 
) 

func main() { 
    res, _ := exec.Command("sh", "-c", "mount | grep /home").Output() 
    fmt.Printf("%s", res) 
} 
1

您可以使用管道语言机器,像

c1 := exec.Command("mount") 
c2 := exec.Command("grep", toDir) 
c2.Stdin, _ = c1.StdoutPipe() 
c2.Stdout = os.DevNull 
c2.Start() 
c1.Run() 
c2.Wait() 
相关问题