Runtime.getRuntime().exec Problem

Ismoh

Mitglied
Ich habe das Forum durchstöbert, aber keine vorhandene Lösung gefunden, deshalb das neue Thema.

Ich starte per
Java:
Runtime.getRuntime().exec("*.exe")
Men of War Vietnam.

Bezüglich des SourceCodes mache ich mir eher weniger Sorgen, jedoch funktionierts nicht richtig...

Java:
private void starteMenOfWar() {
		try {
			Thread.sleep(25000);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
		try {
			System.out.println("Starte Men of War...");
			Runtime.getRuntime().exec(menOfWarPath);			
		} catch (IOException e) {
			e.printStackTrace();
			try {
				file.deleteOnExit();
			} catch (Exception ex) { e.printStackTrace(); }
		}
		System.exit(0);
	}

Anbei findet ihr Screens:
1.png

2.png


Jemand eine Idee zur Problemlösung?
Ich vermute mal, dass ich irgendwelche Parameter übergeben muss oder ähnliches...
Wenn ich nach der Fehlermeldung das Spiel per Mausklick bzw Verknüpfung starte, funktioniert es.
 
Hier der gesamte SourceCode:
Java:
package pg;

import java.io.*;


public class MainClass {

	BufferedReader buffReader, console;
	String steamPath, menOfWarPath, temp, configPath = System.getProperty("user.home") + "/AppData/Roaming/MenOfWarStarterConfig.txt";//"/Local Settings/Application Data/MenOfWarStarterConfig.txt";
	File file;
	
	public static void main(String[] args) {
		new MainClass();
	}
	
	public MainClass() {
		
		erstelleConfig();		
	}
	
	private void erstelleConfig() {		
		try
		{
			file = new File(configPath);
			if(file.exists()) {	
			}
			else {
				FileWriter fileW = new FileWriter(file.getPath());
				
				PrintWriter printW = new PrintWriter(fileW);
				try {
					console = new BufferedReader(new InputStreamReader(System.in));
			        System.out.println("Gib' den \"Steam.exe\"-Pfad an: [ Ersetze '\' mit '\\' oder '/' ]");
			        temp = console.readLine();
		        } catch (IOException e) {
		        	e.printStackTrace();
		        }
				printW.println(temp);
				
				try {
					console = new BufferedReader(new InputStreamReader(System.in));
			        System.out.println("Gib' den \"MenOfWarVietnam.exe\"-Pfad an: [ Ersetze '\' mit '\\' oder '/' ]");
			        temp = console.readLine();
			    } catch (IOException e) {
			        e.printStackTrace();
			    }
				printW.println(temp);
				
				fileW.flush();
				fileW.close();
				
				printW.flush();
				printW.close();
			}
		}
		catch( IOException e ) {
			e.printStackTrace();
		}		
		useConfig();
	}
	
	private void useConfig() {
		try {
			buffReader = new BufferedReader(new FileReader(configPath));
			
			steamPath = buffReader.readLine();
			menOfWarPath = buffReader.readLine();
			System.out.println("SteamPath: " + steamPath);
			System.out.println("MenOfWarPath: " + menOfWarPath);
		} catch (IOException e) {
			e.printStackTrace();
		}
		starteSteam();
	}
	
	private void starteSteam() {
		try {
			System.out.println("Starte Steam...");
			Runtime.getRuntime().exec(steamPath);
			
		} catch (IOException e) {
			e.printStackTrace();
			try {
			file.deleteOnExit();
			} catch (Exception ex) { e.printStackTrace(); }
		}
		starteMenOfWar();
	}
	
	private void starteMenOfWar() {
		try {
			Thread.sleep(25000);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
		try {
			System.out.println("Starte Men of War...");
			Runtime.getRuntime().exec(menOfWarPath);			
		} catch (IOException e) {
			e.printStackTrace();
			try {
				file.deleteOnExit();
			} catch (Exception ex) { e.printStackTrace(); }
		}
		System.exit(0);
	}
}

Men of War Path ist inna txt angegeben 😉
 
[JAVA=25]if(file.exists()) {
}
else {[/code]

Ist das Hauptproblem. Du überprüfst, ob die Datei existiert, und nur, wenn dem nicht so ist willst was mit ihr "machen".

Außerdem würde ich anstatt über user.home an die Anwendungsdaten zukommen eher einfach
Code:
System.getenv("APPDATA");
benutzen.
 
Ich denke mal nicht, dass dort der Fehler ist.
Da es nur daurm geht, die Pfade anzugeben, wenn die txt noch nicht existiert.
Wenn die txt exisitiert und die Pfade angegeben sind startet Steam & Men of War...

ich will ja nicht jedes mal den pfad angeben...
 

Zurück
Oben