0

I am running this code below and I have tried to use the stockfish exe. When running with file path it works although not in jar file. When I use a URL it does not work. My other file paths work just this does not. I think it has to do with it being an exe and using processbuilder.

public Engine()
{
     builder = new ProcessBuilder(getClass().getResource("/cpt_chess/sf.exe"));
     builder.redirectErrorStream(true);
}


public void start_process()
{
    try 
    {
        process = builder.start();
        
    } 
    catch (IOException e) 
    {System.out.print("error");
    }
}



public void read () 
{
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
    
    new Thread ()
    {
        public void run ()
        {
            try {
                String line =  stdInput.readLine();
             
                while (line != null)
                {
                    if (line.contains("bestmove"))
                    {
                        test_chess.engine_move = line;
                    }
                    line =  stdInput.readLine();
                }
            } catch (IOException ex) {
                Logger.getLogger(Engine.class.getName()).log(Level.SEVERE, null, ex);
            }
            
        }
    }.start();
}
Surgelt3
  • 11
  • 2
  • Does this answer your question? [Run exe which is packaged inside jar file](https://stackoverflow.com/questions/600146/run-exe-which-is-packaged-inside-jar-file) – maloomeister May 11 '21 at 06:31

1 Answers1

2

You can't. Windows doesn't allow you to execute files directly from ZIP / JAR files.

What you can do is unpack those files. Use System.getProperty("java.io.tmpdir") to get the path to the temporary files folder, then copy those files there. You can use Class.getResourceAsStream("/qemu.exe") etc to retrieve InputStreams to them.