github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/utils/system.go (about) 1 package utils 2 3 import ( 4 "os" 5 "os/exec" 6 "syscall" 7 ) 8 9 func System(cmd string) int { 10 c := exec.Command("sh", "-c", cmd) 11 c.Stdin = os.Stdin 12 c.Stdout = os.Stdout 13 c.Stderr = os.Stderr 14 if err := c.Run(); err == nil { 15 return 0 16 } 17 18 // Figure out the exit code 19 if ws, ok := c.ProcessState.Sys().(syscall.WaitStatus); ok { 20 if ws.Exited() { 21 return ws.ExitStatus() 22 } 23 24 if ws.Signaled() { 25 return -int(ws.Signal()) 26 } 27 } 28 29 return -1 30 }