Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 09-28-2008, 08:29 PM   #1 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Need Java help

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.
__________________

Need website help? PM me!
CrazeD is offline  
Old 09-28-2008, 10:51 PM   #2 (permalink)
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

Default Re: Need Java help

Take a look at this function reference

Runtime (Java 2 Platform SE v1.4.2)

In there you'll see that there are 2 other arguments that you can pass to the .exec function of getRunTime.

One is envp, which is a reference to an environment. You shouldn't need a custom environment, but you may need to get a reference to the current one. (no idea how to do this)

The other is the Working directory, which is what you're talking about needing.
__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline  
Old 09-28-2008, 11:39 PM   #3 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Need Java help

I looked through that and don't understand what I'm suppose to do. I just sat here for like an hour Googleing about envp and exec(), and I'm really confused now. :s

Can you give me some example code?
__________________

Need website help? PM me!
CrazeD is offline  
Old 09-29-2008, 05:56 PM   #4 (permalink)
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

Default Re: Need Java help

It's been a long time since I've programmed in java, but here's a hack away at it.

Code:
String file="d:\\games\\cod4\\iw3mp.exe -+"+ip+" -+"+pass;
File workingdir = "d:\\games\\cod4"
		Runtime.getRuntime().exec(file, "", workingdir);
If it complains about the envp, give this a try

Code:
String file="d:\\games\\cod4\\iw3mp.exe -+"+ip+" -+"+pass;
File workingdir = "d:\\games\\cod4"
		Runtime.getRuntime().exec(file, System.GetEnv, workingdir);

__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline  
Old 09-29-2008, 06:29 PM   #5 (permalink)
CrazeD's Avatar
 
Wizard Techie

Join Date: Feb 2006

Location: Maine

Posts: 3,683

CrazeD will become famous soon enough

Send a message via AIM to CrazeD Send a message via MSN to CrazeD
Default Re: Need Java help

Using this:

Code:
String file="f:\\games\\cod4\\iw3mp.exe -+"+ip+" -+"+pass;
		
File workingdir = "f:\\games\\cod4";
Runtime.getRuntime().exec(file,"",workingdir);
I get this error:

Code:
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
Type mismatch: cannot convert from String to File
The method exec(String, String[], File) in the type Runtime is not applicable for the arguments (String, String, File)

at OpenExe.main(OpenExe.java:21

__________________

Need website help? PM me!
CrazeD is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Updates for Java eliminate many security holes Trotter Browser & General Internet Questions 1 07-11-2008 09:54 PM
Some Java Questions Redavni Programming Discussions 1 06-30-2008 09:55 AM
Java / Adobe Question Tempest Browser & General Internet Questions 3 11-07-2007 05:53 PM
Dangerous Java Flaw Threatens Virtually Everything Osiris Virus - Spyware Protection / Detection 1 07-13-2007 04:44 PM
Java Game Yek Programming Discussions 5 06-16-2007 04:29 AM