在golang中调用ping命令为什么不能像windows命令行输出呢?我是新手

1283292280 · 2016-09-29 15:05:09 · 3265 次点击

%s the uninterpreted bytes of the string or slice

试试 %T a Go-syntax representation of the type of the value

#3
更多评论
stevewang
耶和华是我的牧者,我必不至缺乏。

ping命令有对应的执行文件,不需要在cmd里执行。

package main

import (
    "os"
    "os/exec"
)

func main() {
    cmd := exec.Command("ping", "127.0.0.1")
    cmd.Stdout = os.Stdout
    cmd.Run()
}
#1

line 改成 string(line) 试下 或者可以看下我这里的http://blog.csdn.net/zistxym/article/details/8672763的例子

#2