I'm on a JSF application, I have a .bat
that I want to launch when clicking on a Command
button, this script is in the webcontent directory of my project.
The code of the action is:
public String genererRapportTable() {
try {
ServletContext ctx = (ServletContext) FacesContext
.getCurrentInstance().getExternalContext().getContext();
String realPath = ctx.getRealPath("/");
String[] command = { "cmd.exe", "/C", "start", realPath + "Tools\\cmd.bat" };
Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
The path is correctly constructed but the script is not launched!
The debugging screen:
This what I get for output :
So the path is correct but the script is not launched. When I put the .bat
on c:\Tools
and I use this path "C:\\Tools\\cmd.bat"
it works.
What is the problem?