-3

I am trying to use variables within the string

i have tried the following to no avail :(

astatus, _ := exec.Command("/bin/sh", "-c", "fs_cli -x\"callcenter_config agent get status\"", agent_uuid).Output()
astatus, _ := exec.Command("/bin/sh", "-c", "fs_cli -x\"callcenter_config agent get status\"" + agent_uuid).Output()

it does not seem to be parsing the output of the variable agent_uuid

any help would be much appreciated

MikeyR
  • 5
  • 1

1 Answers1

0

You didn't provide an example of a correct command line invocation, and I'm not familiar with fs_cli. But I think your issues here is a quesiton of whitespace for the shell command.

astatus, _ := exec.Command("/bin/sh", "-c", "fs_cli -x\"callcenter_config agent get status\"", agent_uuid).Output()

That's going to produce a shell invocation such as:

/bin/sh -c" "fs_cli -x\"callcenter_config agent get status\"" agent_uuid

Because that's how you did the spaces. but looking at the fs_cli data online, it should probably be something more like:

"/bin/sh", "-c", "fs_cli -x \"callcenter_config agent get status agent_uuid\"" 

Actually there's really no purpose in using a shell command. You aren't using any bash features - it's just a passthrough to executing another program. So instead of formatting for shell, just invoke the program directly. Then, each argument will be a separate string, and you won't have to worry about whitespace:

astatus, err := exec.Command(
   "fs_cli",
   "-x",
   fmt.Sprintf("callcenter_config agent get status %s", agent_uuid),
).Output()

If you can't get this working, please make sure to edit the question with the exact invocation of fs_cli that you use at command line, with the whitespace in the correct place. Then it will be an easy matter to fix the invocation here.

astatus, _ := exec.Command(...)

Don't ever ignore errors in Go. Remember it doesn't raise exceptions - checking error status is generally the only way to detect runtime errors. You're hurting your own debugging by ignoring the error that might come from the command invocation.

erik258
  • 14,701
  • 2
  • 25
  • 31