我写了一个Go cli程序并使用Windows cmd运行它。 然后执行以下命令:
db2cmd -c DB2 RESTORE DATABASE DMSCNDB FROM "C:/DB" TAKEN AT 20180522033009 ON C: INTO DMSCNDB WITHOUT PROMPTING
以下是我使用的Go代码:
cmd := exec.Command("db2cmd", "-c", arg)
buf, err := cmd.Output()
if err != nil {
log.Fatalf("Failed restoring backup with error: %s\r\n", err)
} else {
log.Printf("Successfully restored backup with command output: %s\r\n", buf)
}
除db2cmd
生成的命令提示符外,其他所有内容都被罚款。有没有办法得到它的输出?如何通过db2cmd
运行DB2命令的输出?
谢谢!
答案 0 :(得分:0)
所以,只需使用-i
参数,如下所示:
cmd := exec.Command("db2cmd", "-i", arg)
buf, err := cmd.Output()
if err != nil {
log.Fatalf("Failed restoring backup with error:\r\n%s\r\n", err)
} else {
log.Printf("Successfully ran command with output:\r\n%s\r\n", buf)
}