replace에 다음 실행 파라미터도 넘길 수 있음

This commit is contained in:
2023-06-14 01:50:25 +09:00
parent 3add5d9355
commit 2e4b7811db

View File

@ -1,6 +1,7 @@
package main
import (
"encoding/json"
"errors"
"io"
"log"
@ -70,7 +71,7 @@ func main() {
selfext, _ := os.Executable()
selfext = path.Base(selfext)
nextArgs := args[4:]
entries, _ := os.ReadDir(args[2])
for _, ent := range entries {
if ent.Name() == selfext {
@ -82,7 +83,14 @@ func main() {
stdlog.Fatal(err)
}
} else {
if err := copy(path.Join(args[2], ent.Name()), ent.Name()); err != nil {
if ent.Name() == "@args" {
var tempArgs []string
argfile, _ := os.Open(path.Join(args[2], ent.Name()))
dec := json.NewDecoder(argfile)
if dec.Decode(&tempArgs) == nil {
nextArgs = tempArgs
}
} else if err := copy(path.Join(args[2], ent.Name()), ent.Name()); err != nil {
stdlog.Println("copy failed :", path.Join(args[2], ent.Name()), ent.Name())
stdlog.Fatal(err)
}
@ -100,6 +108,6 @@ func main() {
}
stdlog.Println("exec.Command :", args)
cmd := exec.Command(args[3], args[4:]...)
cmd := exec.Command(args[3], nextArgs...)
cmd.Start()
}