l want to be able to run a bat file compiled in my java app. Everything runs fine from the netbeans IDE but when l build and run, the cmd is not able to run the resource file bundled in the jar file. l run the bat file with cmd(Runtime in java). From the image below, the application package is the apksec, and others are resource folders with files l want to use in the program, the bat file is in the res folder, When l run the app directly from cmd
C:\Users\slab1>java -jar C:\Users\slab1\Pictures\training\dist\ApkSec.jar
l get error
'file:' is not recognized as an internal or external command,
The code snippet to run the bat file using cmd below
How can l get a path to run the bundled resource file in the jar?
Please take care of parameters you are passing to exec method. Here is an example from - https://www.tutorialspoint.com/java/lang/runtime_exec_envp.htm
public static void main(String[] args) {
try {
// create a new array of 2 strings
String[] cmdArray = new String[2];
// first argument is the program we want to open
cmdArray[0] = "notepad.exe";
// second argument is a txt file we want to open with notepad
cmdArray[1] = "example.txt";
// print a message
System.out.println("Executing notepad.exe and opening example.txt");
// create a process and execute cmdArray and currect environment
Process process = Runtime.getRuntime().exec(cmdArray,null);
// print another message
System.out.println("example.txt should now open.");
} catch (Exception ex) {
ex.printStackTrace();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.