I'm currently using os/exec
to run many psql
commands in sequence.
My problem is that if there's an error during the execution of the script, the output doesn't show it.
Example: When executing the command file from the command line, the output is this:
SET
CREATE FUNCTION
psql:update-14.3.7.1/dml/----------------xxxxxxxx.sql:33: ERROR: null value in column "tipoxxxxxxxx" violates not-null constraint
DETALHE: Failing row contains (9, 0, null, null, null, null, AAAAAAAAA_BBBBBBBBBB_CCCCC_BANANA, null, null, null).
CONTEXTO: SQL statement "insert INTO ----------------xxxxxxxx
(id,versao,tipoxxxxxxxx,carrotdeapplefinal,carrotdetttttttt,ativa,funcionalidade,driver,alterar_na_xxxxxxxx)
values
(nextval('sq_----------------xxxxxxxx'),0,tipoaaaaaaaaa,carrotapple,carrottttttttt,alterarNaxxxxxxxx)"
PL/pgSQL function createorupdateaaaaaaaaa() line 22 at SQL statement
DROP FUNCTION
And executing the exact same file from the Go code, the output is:
SET
CREATE FUNCTION
DROP FUNCTION
My Go code for running commands(and showing the output) is:
cmd := exec.Command(comando, argList...)
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
cmdS := out.String()
fmt.Println("cmdS", cmdS)
if err != nil {
fmt.Println("XYZ")
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
}
How to modify my code to show the other lines of the output?