暂存

tmp
This commit is contained in:
2024-05-09 16:35:21 +08:00
parent 3afa0d81bb
commit bcc1b51006
27 changed files with 1526 additions and 0 deletions

46
shell/shell.go Normal file
View File

@@ -0,0 +1,46 @@
package shell
import (
"log"
"os"
"os/exec"
"path/filepath"
)
func ExecuteOne(name string, args ...string) {
KillAll(name)
Execute(name, args...)
}
func Execute(name string, args ...string) {
// get the directory of the executable
file, err := os.Executable()
if err != nil {
log.Fatal("Error getting executable path:", err)
}
dir := filepath.Dir(file)
// change the current working directory to the directory of the executable
err = os.Chdir(dir)
if err != nil {
log.Fatal("Error changing working directory:", err)
}
log.Println("Executing command:", name, args)
cmd := exec.Command(name, args...)
// cmd.Stderr = os.Stderr
// cmd.Stdout = os.Stdout
err = cmd.Run()
if err != nil {
log.Println("Error executing command:", name, args, err)
}
}
func KillAll(name string) {
cmd := exec.Command("pkill", "-f", name)
err := cmd.Run()
if err != nil {
log.Println("Error killing all processes with name:", name, err)
}
}