I am trying to write a small Go wrapper application around the 1Password CLI executable op
like so:
package main
import (
"fmt"
"log"
"os/exec"
)
func main() {
op := exec.Command("op", "item", "list")
out, err := op.Output()
if e, ok := err.(*exec.ExitError); ok {
log.Fatal(e, ": ", string(e.Stderr))
}
fmt.Println(string(out))
}
However, I keep getting the following error:
2023/04/13 09:48:51 exit status 1: [ERROR] 2023/04/13 09:48:51 error initializing client: connecting to desktop app: read: connection reset, make sure the CLI is correctly installed and Connect with 1Password CLI is enabled in the 1Password app
But when I do the same thing from a Python script like so:
#!/usr/bin/env python
import subprocess
subprocess.run(["op", "item", "list"])
...I get the output just fine.
Interestingly enough though, when I call the Python script (named op.py
) from the Go app, it works fine (modified Go app shown below):
package main
import (
"fmt"
"log"
"os/exec"
)
func main() {
op := exec.Command("/usr/bin/python3.11", "./op.py")
//op := exec.Command("op", "item", "list")
out, err := op.Output()
if e, ok := err.(*exec.ExitError); ok {
log.Fatal(e, ": ", string(e.Stderr))
}
fmt.Println(string(out))
}
I can test that it is being printed by the Go app and not by the Python script because if I remove the fmt.Printf(...)
, nothing gets printed.
So to summarize:
- Go ->
op
: does not work - Python (
./op.py
) ->op
: works fine - Go -> Python (
./op.py
) ->op
: works fine