我正在尝试使用Go:
import (
"log"
"os/exec"
"strings"
)
func verifyPythonVersion() {
_, err := exec.LookPath("python")
if err != nil {
log.Fatalf("No python version located")
}
out, err := exec.Command("python", "--version").Output()
log.Print(out)
if err != nil {
log.Fatalf("Error checking Python version with the 'python' command: %v", err)
}
fields := strings.Fields(string(out))
log.Print(fields)
}
func main() {
verifyPythonVersion()
}
这将返回空切片:
2014/01/03 20:39:53 []
2014/01/03 20:39:53 []
知道我做错了什么吗?你知道吗
我们可以得出结论,输出到stderr。现在我看了一下Go的文档,猜猜看,
cmd.Output
只捕获stdout(docs)。您应该使用cmd.CombinedOutput
(docs):相关问题 更多 >
编程相关推荐