summaryrefslogtreecommitdiff
path: root/restart_windows.go
blob: 4e239dd053aea722c6c43f086cebf0e834630562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main

import (
	log "github.com/sirupsen/logrus"
	"os"
)

func restart() {
	if _, err := os.Stat(executable); err != nil {
		log.Fatalf("Unable to get executable path, %s", err)
		os.Exit(1)
	}
	log.Infof("Program found at %s.", executable)
	wd, err := os.Getwd()
	if err != nil {
		log.Fatalf("Unable to get working directory, %s", err)
		os.Exit(1)
	}
	log.Infof("Current working directory is %s.", wd)
	_, err = os.StartProcess(executable, []string{}, &os.ProcAttr{
		Dir:   wd,
		Env:   nil,
		Files: []*os.File{os.Stderr, os.Stdin, os.Stdout},
		Sys:   nil,
	})
	if err != nil {
		log.Fatalf("Unable to create new process, %s", err)
		os.Exit(1)
	}
}