Permission denied (fork/exec)

Hello, I’m trying
to execute this code:

package main

import (
	"fmt"
	"log"
	"uci"
)

func main() {
	eng, err := uci.NewEngine("./Stockfish-master/src")
	if err != nil {
		log.Fatal(err)
	}
	
	// set some engine options
	eng.SetOptions(uci.Options{
		Hash:128,
		Ponder:false,
		OwnBook:true,
		MultiPV:4,
	})

	// set the starting position
	eng.SetFEN("rnb4r/ppp1k1pp/3bp3/1N3p2/1P2n3/P3BN2/2P1PPPP/R3KB1R b KQ - 4 11")
	
	// set some result  filter options
	resultOpts :=  uci.HighestDepthOnly | uci.IncludeUpperbounds |  uci.IncludeLowerbounds
	results,_ := eng.GoDepth(10, resultOpts)

	// print it
	fmt.Println(results)
}

This code calls:

package uci

import (
	"bufio"
	"encoding/json"
	"fmt"
	"log"
	"os/exec"
	"sort"
	"strconv"
	"strings"
	"text/scanner"
)

type Engine struct {
	cmd  *exec.Cmd
	stdout *bufio.Reader
	stdin *bufio.Writer
}

// NewEngine returns an Engine it has spun up
// and connected  communication to
func NewEngine(path string) (*Engine, error) {
	eng := Engine{}

   //FAIL IN THIS LINE
	eng.cmd = exec.Command(path)

	stdin, err :=  eng.cmd.StdinPipe()
	if err != nil {
		return nil, err
	}
	stdout, err := eng.cmd.StdoutPipe()
	if err != nil {
		return nil, err
	}
	if err := eng.cmd.Start(); err != nil {
		return nil, err
	}
	eng.stdin = bufio.NewWriter(stdin)
	eng.stdout = bufio.NewReader(stdout)
	return &eng, nil
}

When I execute I have the following problem:

2016/07/18 22:16:12 fork/exec ./Stockfish-master/src: permission denied

I execute the program as sudo (sudo ./execute), but I have the same result.
My version of Go is: go version go1.6.2 linux/amd64
I don’t know why my program doesn’t enough permissions to execute this command.
This program is UCI which communicate with Stockfish (Chess engine)

Many thanks in advance.

Is this in fact the path to your executable, and if so what are the permissions on it?

ls -l ./Stockfish-master/src

1 Like

Probably “”./Stockfish-master/src" is a directory. AFAIK (in other programming language), exec must point to executable file.

1 Like

Yes. “./Stockfish-master/src” is a directory. My idea was that my program execute the main class inside of “src”. Now, I know that I need to point to executable file.

Many thanks for your help.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.