Ich habe über Exec in Go https://gobyexample.com/execing-processes gelesen und versucht, das gleiche mit Gououtines zu tun.Haupt-Thread läuft nicht nach Goroutine Anrufe Exec?
Im folgenden Code versuche ich Go ls
ausführen, dann eine Erfolgsmeldung im Hauptthread drucken. Es wird jedoch nur die ls, aber nicht die Erfolgsmeldung gedruckt.
Was ist los?
Danke.
package main
import "syscall"
import "os"
import "os/exec"
import "fmt"
func main() {
p := fmt.Println
done := make(chan bool)
binary, lookErr := exec.LookPath("ls")
if lookErr != nil {
panic(lookErr)
}
args := []string{"ls", "-a", "-l", "-h"}
env := os.Environ()
go func() {
execErr := syscall.Exec(binary, args, env)
if execErr != nil {
panic(execErr)
}
done <- true
}()
<-done
p("Done with exec")
}
Hier ist der Ausgang:
Valeriys-MacBook-Pro:test valeriy$ go run test.go
total 8
drwxr-xr-x 3 valeriy staff 96B Dec 17 15:46 .
drwxr-xr-x 8 valeriy staff 256B Dec 17 00:06 ..
-rw-r--r-- 1 valeriy staff 433B Dec 17 15:38 test.go