I'm new to Java, so this is quite confusing to me. I am experienced in PHP and other languages so have a bit of programming logic already, but I'm not quite familiar with Java yet.
So, I want to start an application, namely, Call of Duty 4 via my program. I want a couple parameters along with it. The purpose is to connect to a server based on a users input which has the IP/password.
I got that down, I just need help making it execute from anywhere based on an absolute path. If I just specify "iw3mp.exe" (the name of the game exe) and stick it in the same folder, everything works. However that is a cheap fix and I don't like, I want an absolute path.
So here's my code so far:
This code currently works if I put the jar in the same folder as the iw3mp.exe. As said, I want it to work from anywhere based on this path: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); } }
"f:\games\cod4\iw3mp.exe"
I posted this on another forum and was shown this:
I tried messing with this and I couldn't make it work.exec(String[] cmdarray, String[] envp, File dir)
Executes the specified command and arguments in a separate process with the specified environment and working directory.
I tried this, from a suggestion off another forum, but it doesn't work - I get this compile error:Code:String file="f:\\games\\cod4\\iw3mp.exe -+"+ip+" -+"+pass; String workingdir = "f:\\games\\cod4"; Runtime.getRuntime().exec(file,"",workingdir);
I have tried various other ways but have not gotten it to work, so I need some help. Thanks.The method exec(String, String[], File) in the type Runtime is not applicable for the arguments (String, String, String)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks