Okay so I have to write a .bat file to open the DOS window so I can run my CS Project. Yes I know that I can just open the cmd window, but the professor wants us to write a .bat file to open the cmd window. Anyone know how to write a .bat file to open the cmdwindow? By the way I'm coding in Java, if that makes a difference
-4
-
2A batch file isn't relevant to Java really. It's a file containing lines of window commands. Have you even looked into batch files before asking on here? And you aren't very clear about how it should work. Should it open a DOS window, then you can manually type in the location of your project to run it? Or should it run your application without displaying a window? -1 for no effort. We aren't here to do your homework – Vince Emigh Apr 28 '14 at 15:48
1
You can do this using Runtime
Class. Create .bat file and placed in the project home directory.
In my Example testbat.bat contains START cmd.exe.
These will be altogether a combination of "Java + Bat + Cmd"
Try this : Tested and Executed.
//your package here
import java.io.*;
public class TestExec {
public static void main(String[] args) {
try {
Process p = Runtime.getRuntime().exec("testbat.bat");
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
-
-
-
Thank you so much man, although the code you gave me didn't help me much the part where you stated that your .bat file contains "START cmd.exe" helped me so much thank you man. I know how to write a .bat file I just didn't know what to write in it so it could open up the DOS window – tonyisapony Apr 28 '14 at 21:07