I wrote a C program that simply delete the folder called myFolder.txt
I want to execute the .exe file from a java application.
So, I used the following code:
try
{
Runtime rt = Runtime.getRuntime() ;
Process p = rt.exec("program2.exe") ;
p.destroy() ;
}catch(Exception exc){/*handle exception*/
System.out.println("ERROR");
}
When I run my java application no error appears but the file is not deleted.
Why?
You have created a process, and then immediately destroyed it. Of course the executable won’t run. Try calling
.waitFor()instead (or just let it run).