i've got a problem with my go code. I'll try to build a script to automate my update and installing with syscall.
package main
import (
"fmt"
"os"
"os/exec"
"syscall"
)
func update() {
binary, lookErr := exec.LookPath("apt")
if lookErr != nil {
panic(lookErr)
}
args := []string{"apt", "update"}
env := os.Environ()
execErr := syscall.Exec(binary, args, env)
if execErr != nil {
panic(execErr)
}
}
func upgrade() {
binary, lookErr := exec.LookPath("apt")
if lookErr != nil {
panic(lookErr)
}
args := []string{"apt", "upgrade", "-y"}
env := os.Environ()
execErr := syscall.Exec(binary, args, env)
if execErr != nil {
panic(execErr)
}
}
func main() {
update()
upgrade()
}
The code is only doing the first update() function. After that is canceling. No errors or anything. How could i manage to do it step by step?
To cite the manual:
The
exec()
family of functions replaces the current process image with a new process image.
(Emphasis mine).
To solve this, use the functions from os/exec
and handle all the errors.