This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I constantly have to access the command prompt to execute a particular command. The command is always the same except for one parameter, which is in the middle of the command. I started writing a batch file that would prompt me for the one parameter and execute the command.
However, I thought it would be pretty easy to write a Java program that would prompt for the the parameter and execute the command in the Windows command prompt. I thought that maybe the Java program would have to call the batch file, but I don't think this would be preferable. For one, I'm not sure if the Java program can accept an input and then pass said input to a batch file.
Would this be a good idea for a quick Java program or would it be a better idea to write a program like this in a different language? I'm taking a Java class now, but I have no idea how to execute commands in the Windows command prompt from Java.
You can use exec() in the Runtime class to execute other processes. The process path has to exist in the path variable or you have to mention the fully qualified process name, like c:\usr\bin\example.exe