I wrote a Go cli program and ran it with Windows cmd. It then executed the following command:
db2cmd -c DB2 RESTORE DATABASE DMSCNDB FROM "C:/DB" TAKEN AT 20180522033009 ON C: INTO DMSCNDB WITHOUT PROMPTING
Here is the Go code I used:
cmd := exec.Command("db2cmd", "-c", arg)
buf, err := cmd.Output()
if err != nil {
log.Fatalf("Failed restoring backup with error: %s
", err)
} else {
log.Printf("Successfully restored backup with command output: %s
", buf)
}
Everything worked fined, except for the command prompt spawned by the db2cmd
. Is there any way to get the output of it? How can I get the output of DB2 command run by db2cmd
?
Thank you!
I have found the answer here: https://www.ibm.com/support/knowledgecenter/en/SSEPGG_10.5.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0002036.html
So, just use the -i
parameter like this:
cmd := exec.Command("db2cmd", "-i", arg)
buf, err := cmd.Output()
if err != nil {
log.Fatalf("Failed restoring backup with error:
%s
", err)
} else {
log.Printf("Successfully ran command with output:
%s
", buf)
}