Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Find krd.exe relative to current exe.
Browse files Browse the repository at this point in the history
  • Loading branch information
zobo committed Oct 21, 2019
1 parent 4ce243e commit 5de7846
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion kr/kr_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ func uninstallCommand(c *cli.Context) (err error) {
}

func startKrd() (err error) {
cmd := exec.Command("cmd.exe", "/C", "start", "/b", `krd.exe`)
exe := "krd.exe"
if pfx, err := getPrefix(); err == nil {
exe = pfx + `\krd.exe`
}
cmd := exec.Command("cmd.exe", "/C", "start", "/b", exe)
return cmd.Run()
}

Expand Down
16 changes: 15 additions & 1 deletion socket_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net"
"os"
"os/exec"
"path/filepath"
"time"
)

Expand All @@ -19,10 +20,23 @@ func AgentListen() (listener net.Listener, err error) {
return
}

// TODO too much repeating...
func getPrefix() (string, error) {
if ex, err := os.Executable(); err == nil {
return filepath.Dir(ex), nil
} else {
return "", err
}
}

func DaemonDial(unixFile string) (conn net.Conn, err error) {
if !IsKrdRunning() {
os.Stderr.WriteString(Yellow("Krypton ▶ Restarting krd...\r\n"))
_ = exec.Command("cmd.exe", "/C", "start", "/b", `krd.exe`).Start()
exe := "krd.exe"
if pfx, err := getPrefix(); err == nil {
exe = pfx + `\krd.exe`
}
_ = exec.Command("cmd.exe", "/C", "start", "/b", exe).Start()
<-time.After(1 * time.Second)
}
conn, err = net.Dial("unix", unixFile)
Expand Down

0 comments on commit 5de7846

Please sign in to comment.