সোমবার, ৮ নভেম্বর, ২০১০

Create Bat file and Run Bat by java code

1. create Bat file:
Sample: (opens calculator on Windows XP, might not work on other versions if calc.exe location is different. Process is the same though.)

1) Open notepad

2) copy and paste the following line (with quotes) into notepad. It will be the only line.

"C:\WINDOWS\system32\calc.exe"


3) Click File -> Save As...

4) Change the "Text Documents" drop down box to say "All Files"
5) type calc.bat in the name field
6) Save it where you want it
7) Run it

2. Run Batch file from java code

public class BatchTest {

/**
* Creates a new instance of BatchTest.
*/
public BatchTest() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

Runtime rut = Runtime.getRuntime();
try {
rut.exec(new String[] {"C:\\batchTest.bat"} );
} catch (Exception e1) {
e1.printStackTrace();
}
}
}



courtesy by: yahoo.answer and techfuels.com

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন