prevent crash of soldier when binary is not found

Signed-off-by: Leo Chen <leo@harmony.one>
pull/69/head
Leo Chen 6 years ago
parent 75fa0ceb79
commit 395782e28a
  1. 6
      utils/utils.go

@ -3,7 +3,10 @@ package utils
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"log"
"os"
"os/exec"
"regexp"
"strconv"
@ -34,6 +37,9 @@ func GetUniqueIdFromPeer(peer p2p.Peer) uint16 {
// RunCmd Runs command `name` with arguments `args`
func RunCmd(name string, args ...string) error {
if _, err := os.Stat(name); os.IsNotExist(err) {
return errors.New(fmt.Sprintf("file: %v doesn't exist", name))
}
cmd := exec.Command(name, args...)
if err := cmd.Start(); err != nil {
log.Fatal(err)

Loading…
Cancel
Save