CreateProcess error = 5, access denied. [How to Solve]

CreateProcess error = 5, access denied.

Bugs encountered using java runtime. Getruntime(). Exec()

Bugs encountered using java runtime. Getruntime(). Exec()

Today, when using a wkhtmltopdf tool, you need to use a Java method, * runtime. Getruntime() returns the runtime object of the current application, and the exec() method of the object instructs the Java virtual machine to create a child process, execute the specified executable program, and return the process object instance corresponding to the child process. Through process, you can control the execution of the sub process or obtain the information of the sub process* An introduction link to this function is attached: runtime. Getruntime(). Exec()
when an error code is reported, guess that the reason is that the folder cannot be accessed or the command cannot be called.

public class WKTest {
    public static void main(String[] args) {
        String cmd = "D:/programfiles/wkhtmltopdf/bin --quality 75 https://www.nowcoder.com D:\\work\\wk-images/3.png";

        try{
            Runtime.getRuntime().exec(cmd);
            System.out.println("ok");
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}

java.io.IOException: Cannot run program "D:/programfiles/wkhtmltopdf/bin": CreateProcess error=5,Denied to access.
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
	at java.lang.Runtime.exec(Runtime.java:620)
	at java.lang.Runtime.exec(Runtime.java:450)
	at java.lang.Runtime.exec(Runtime.java:347)
	at com.nowcoder.community.WKTest.main(WKTest.java:15)
Caused by: java.io.IOException: CreateProcess error=5, Denied to access.

In Java, runtime. Getruntime().Exec() implements calling the server command script to execute the required functions. In other words, this line of code cannot be operated on the folder. You must access the script in the folder. Here I mainly call an. EXE file, which is modified as follows:

public class WKTest {
    public static void main(String[] args) {
        String cmd = "D:/programfiles/wkhtmltopdf/bin/wkhtmltoimage.exe --quality 75 https://www.nowcoder.com D:\\work\\wk-images/3.png";

        try{
            Runtime.getRuntime().exec(cmd);
            System.out.println("ok");
        }catch(IOException e){
            e.printStackTrace();
        }
    }
}

Normal test:

ok

Process finished with exit code 0

Read More: