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:
- [Solved] java.security.AccessControlException: Access Denied Error
- [Solved] hadoop Error: 9000 failed on connection exception java.net.ConnectException Denied to Access
- Java Processbuilder Calls the command error: CreateProcess error = 2
- JAVA: Random access file is always garbled
- [Solved] XxlJob Error: XxlJobFileAppender [101] -| Permission denied
- [Solved] Rocketmq Root Account Startup Error: Permission denied
- [Solved] Tomcat configurate HTTPS error: java.net.SocketException: Permission denied
- [Solved] Springboot Error: swagger-UI/index.html Access Error 404
- error:unable to access jarfile cracker2017.jar [How to Solve]
- The Java class generated by protocol reports an error: cannot access
- [Solved] swagger Docmentation Access Error: Illegal DefaultValue 1024 for parameter type integer, java.lang.NumberFormatException
- [Solved] Activity jump permission UID Error: ActivityTaskmanager: Permission Denied
- Springboot integrates Redis annotation and access error: java.io.NotSerializableException: com.demo.entity.MemberEntity
- JAVA Error Illegal access: this web application instance has been stopped already. Could not load net.sf
- Redis: DENIED Redis is running in protected mode [How to Solve]
- [Solved] failed on connection exception: java.net.ConnectException: Connection denied
- [Solved] No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.errError: Network Error
- [Solved] SpringBoot Create Project and Failed to Access localhost:8080 Error
- [Solved] jar file Execute Error: power shell error: unable to access jarfile
- Springboot WARNING: An illegal reflective access operation has occurred