我目前正在使用顺序os/exec运行许多命令。psql我的问题是,如果在脚本执行期间出现错误,输出不会显示它。示例:从命令行执行命令文件时,输出如下:SETCREATE FUNCTIONpsql:update-14.3.7.1/dml/----------------xxxxxxxx.sql:33: ERROR: null value in column "tipoxxxxxxxx" violates not-null constraintDETALHE: 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 statementDROP FUNCTION并从 Go 代码中执行完全相同的文件,输出为:SETCREATE FUNCTIONDROP FUNCTION我用于运行命令(并显示输出)的 Go 代码是: 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()) }如何修改我的代码以显示输出的其他行?
- 1 回答
- 0 关注
- 130 浏览
添加回答
举报
0/150
提交
取消