A
A
Alex Plotnikov2018-07-19 17:24:58
go
Alex Plotnikov, 2018-07-19 17:24:58

Why is exec.Command not being executed?

Hello, I've encountered some strange problem while executing exec.Command

PGDumpCmd := "pg_dump"
       Path := fmt.Sprintf("/tmp/backup_%v_%v.sql.tar.gz", dbname, time.Now().Unix())
  options := "-h " +  opts.PostgresHost +
    " -p " +  opts.PostgresPort +
    " -U " + opts.PostgresUsername +
    " -d " + dbname +
    " -w -Fc -f " + Path

  log.Printf("[INFO]CMD  command %+v opts %+v ", PGDumpCmd, options)

  cmd := exec.Command(PGDumpCmd, options)
  log.Printf("[INFO]CMD  obj  %+v ", cmd)

  err := cmd.Run()

  if err != nil {
    log.Printf("[INFO]CMD  Error %+v ", err)
  }

returns "Exit Status 1"
although if you copy-paste the output from here log.Printf("[INFO]CMD command %+v opts %+v ", PGDumpCmd, options) and just execute from the console, then everything works fine.
What can be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Pavlyuk, 2018-07-19
@TrueDevs

Your team is given only one flag, which is a concatenation of all flags.
You have to send them separately.

exec.Command("pgdump", "-h", opts.PostgresHost, "-p", opts.PostgresPort, "-U", opts.PostgresUsername, "-d", dbname, "-w", "Fc", "-f ", Path)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question