doulan8846 2019-01-25 10:45
浏览 76
已采纳

执行psql命令时os / exec上的输出不完整

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?

展开全部

  • 写回答

1条回答 默认 最新

  • dongshuo9350 2019-01-25 11:26
    关注

    Programs can use stderr and stdout however they choose. The presence of an execution error has no bearing on whether there was something written to stderr or not.

    Always check both streams when looking for all output from a program.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 代写uni代码,app唤醒
  • ¥15 全志t113i启动qt应用程序提示internal error
  • ¥15 ensp可以看看嘛.
  • ¥80 51单片机C语言代码解决单片机为AT89C52是清翔单片机
  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
  • ¥15 网上下载的3DMAX模型,不显示贴图怎么办
  • ¥15 关于#stm32#的问题:寻找一块开发版,作为智能化割草机的控制模块和树莓派主板相连,要求:最低可控制 3 个电机(两个驱动电机,1 个割草电机),其次可以与树莓派主板相连电机照片如下:
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部