re-init
暂存 tmp
This commit is contained in:
46
shell/shell.go
Normal file
46
shell/shell.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user