diff --git a/main.go b/main.go index 01e907fc..ce628f23 100644 --- a/main.go +++ b/main.go @@ -6,14 +6,13 @@ import ( "log" "net" "os" - "os/exec" "path/filepath" "runtime" "runtime/pprof" ) var ( - envPath = os.Getenv("PATH") + envPath = os.Getenv("PATH") envLevel = os.Getenv("LF_LEVEL") ) @@ -42,7 +41,7 @@ func init() { } func startServer() { - cmd := exec.Command(os.Args[0], "-server") + cmd := detachedCommand(os.Args[0], "-server") if err := cmd.Start(); err != nil { log.Printf("starting server: %s", err) } diff --git a/os.go b/os.go index c43f5fdf..c2cf5a3d 100644 --- a/os.go +++ b/os.go @@ -80,6 +80,10 @@ func init() { gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username)) } +func detachedCommand(name string, arg ...string) *exec.Cmd { + return exec.Command(name, arg...) +} + func pauseCommand() *exec.Cmd { cmd := `echo echo -n 'Press any key to continue' diff --git a/os_windows.go b/os_windows.go index 15f7aaf6..1e4116d6 100644 --- a/os_windows.go +++ b/os_windows.go @@ -7,6 +7,7 @@ import ( "os/user" "path/filepath" "strings" + "syscall" ) var ( @@ -70,6 +71,12 @@ func init() { gHistoryPath = filepath.Join(data, "lf", "history") } +func detachedCommand(name string, arg ...string) *exec.Cmd { + cmd := exec.Command(name, arg...) + cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: 8} + return cmd +} + func pauseCommand() *exec.Cmd { return exec.Command("cmd", "/c", "pause") }