7:golang,Command执行后,输出命令行的信息

func DumpSql(dbDir string) error {
    sqlExe := filepath.Join(dbDir, `sqlite3.exe`)
    if !Exist(sqlExe) {
        return fmt.Errorf("not found file:%s", sqlExe)
    }
    dmt := fmt.Sprintf("/c cd %s&%s&sqlite3.exe QQ.db < dump.sql", dbDir, dbDir[0:2])
    cmd := exec.Command(`cmd.exe`, dmt)
    var out bytes.Buffer
    var stderr bytes.Buffer
    cmd.Stdout = &out
    cmd.Stderr = &stderr
    if err := cmd.Run(); err != nil {
        fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
        return err
    }
    fmt.Println("Result: " + out.String())
    return nil
}
        

你可能感兴趣的:(7:golang,Command执行后,输出命令行的信息)