-
Notifications
You must be signed in to change notification settings - Fork 23
/
system.go
50 lines (45 loc) · 1.49 KB
/
system.go
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package utils
import (
"fmt"
"os"
"os/exec"
"strings"
)
var tempDir = os.TempDir()
func restart(executable string, preArgs []string, delay int, chatId int64, msgId int, msgText string) error {
args := []string{fmt.Sprintf("-delay=%d", delay), fmt.Sprintf("-chat=%d", chatId), fmt.Sprintf("-msg_id=%d", msgId), fmt.Sprintf("-msg_text=%s", msgText)}
preArgs = append(preArgs, args...)
cmd := exec.Command(executable, preArgs...)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
if err := cmd.Start(); err != nil {
return err
}
if err := cmd.Process.Release(); err != nil {
return err
}
os.Exit(1)
return nil
}
func Restart(delay int, chatId int64, msgId int, msgText string) error {
// // command := fmt.Sprintf("run main.go -delay=5 -chat=%d -msg=%d", chat.GetID(), u.EffectiveMessage.ID)
// args := []string{fmt.Sprintf("-delay=%d", delay), fmt.Sprintf("-chat=%d", chatId), fmt.Sprintf("-msg_id=%d", msgId), fmt.Sprintf("-msg_text=%s", msgText)}
// command := []string{"run", "main.go"}
// command = append(command, args...)
// // fmt.Println(command)
args := []string{}
executable, err := os.Executable()
if strings.Contains(executable, tempDir) || err != nil {
executable = "go"
args = []string{"run", "main.go"}
}
return restart(executable, args, delay, chatId, msgId, msgText)
// cmd := exec.Command(executable, command...)
// cmd.Stderr = os.Stderr
// cmd.Stdout = os.Stdout
// cmd.Stdin = os.Stdin
// cmd.Start()
// cmd.Process.Release()
// os.Exit(1)
}