If you remember my thread a bit ago asking about how to launch a program with Visual Basic, I now have the problem, but with Java this time. I have decided to learn a full featured and more powerful language instead, and have picked Java.
I made the program I wanted with Autohotkey, however I want it to be more powerful than that so I want to make it with Java now. I know the extreme basic principles of Java, but need a bit of help launching a program.
Now just to refresh, my idea is to make Call of Duty 4 launch and automatically load into a server based on the user's input. I play in a lot of scrims, and we connect to various match servers by copy/pasting the following into the game console:
Code:
/connect 1.1.1.1:28960; password blahblah
I would like to make this easier (because I'm lazy) by just opening a program and pasting it into a input box, and hit ok and voila. Like I said, I made an autohotkey script to do this and it works.
The reason I couldn't get it to work in Visual Basic, I found out, is because I was trying to launch the exe but wasn't launching it from the directory it's in, just simply starting it "outside" the directory. This was an easy fix in Autohotkey but I'm not sure how to do it in Java.
Note that, if I just simply set the path to "iw3mp.exe" (the game exe I need to launch) and put the program inside the same folder, my program works exactly as I want. But I want to be able to launch from anywhere from an absolute path.
K so, onto my code:
Code:
import java.io.*;
import javax.swing.JOptionPane;
public class OpenExe {
public static void main(String[] args)throws IOException {
String serverIP = JOptionPane.showInputDialog("Enter a Server IP!");
String temp[] = null;
temp = serverIP.split(";");
String ip = temp[0];
String pass = temp[1];
pass = pass.trim();
ip = ip.replace("/","");
String file="iw3mp.exe -+"+ip+" -+"+pass;
Runtime.getRuntime().exec(file);
}
}
Now this part here;
Code:
String file="iw3mp.exe -+"+ip+" -+"+pass;
Runtime.getRuntime().exec(file);
If I change that to my absolute path, so:
Code:
String file="d:\\games\\cod4\\iw3mp.exe -+"+ip+" -+"+pass;
Runtime.getRuntime().exec(file);
It doesn't work. To fix it, I need to "be in" the directory first to call the exe. It's hard for me to explain, I'm not good with this stuff yet. I tried Googleing a bit, but couldn't make sense of any results.
Sorry about my novel-of-a-post, but I wanted to make it clear.
Thanks.