Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Executing program from Java program?  (Read 1025 times)
0 Members and 1 Guest are viewing this topic.
Offline Eliwood

Junior Devvie




Stencyl


« Posted 2006-12-31 22:48:45 »

What I have works fine in Windows but doesn't work on OS X. The strange thing about it is that if it's run from the command line in OS X, it works, but using Java, it doesn't work for some reason. To be specific, "nothing" happens. No errors, exceptions, freezing or windows. The program just proceeds as if nothing happened.

Here's the code (slightly modified to make it clearer).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
      Runtime r = Runtime.getRuntime();
     
      try
      {
         String command = "java -Djava.library.path=blah -jar blah.jar";
         r.exec(command);
      }
     
      catch(Exception ex)
      {
         System.out.println("Caught exception " + ex.getMessage());
      }

Online Riven
« League of Dukes »

« JGO Overlord »


Medals: 842
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2007-01-01 13:42:58 »

First of all, what you're doing will probably crash the sub-process anyway, because you're not taking the Process instance and read the out/err streams from it, so eventually the buffers will get full, and block the sub-process execution.

So, take the streams, and while you're at it, print them to your console, as they are very likely to tell you exactly what is happening and why it's not working like you expected.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Eliwood

Junior Devvie




Stencyl


« Reply #2 - Posted 2007-02-08 07:15:03 »

Hmm. Still no luck on this issue (only on Linux and OS X). The streams complain about not allowing spaces in paths despite my enclosing these paths in quotes.


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline noblemaster

« JGO Spiffy Duke »


Medals: 20
Projects: 10


Age of Conquest makes your day!


« Reply #3 - Posted 2007-02-08 08:10:49 »

that's some code I use to run Java Webstart from Windows, Linux and Mac OS X. Sorry it's long - but you should somehow find your solutions inside  Grin (NOTE: replace "javaws" with "java")

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
package king.lib.access;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import javax.swing.JOptionPane;

/**
 * Allows to run a webstart application.
 *
 * @author  Christoph Aschwanden
 * @since  March 30, 2006
 */

public final class WebstartRunner {

 
  /**
   * Private to prevent instantiation of this class.
   */

  private WebstartRunner() {
    // does nothing.
  }
 
  /**
   * Runs the inputted jnlp file.
   *
   * @param jnlp  The location of the online jnlp to run.
   * @param localVersion  The version of the installer we are running to start the jnlp.
   */

  public static void run(String jnlp, int localVersion) {
    // find if OS is windows
    String osName = System.getProperty("os.name").toLowerCase();
    boolean windowsOS = osName.indexOf("windows") >= 0;
    boolean macOSX = osName.indexOf("mac os x") >= 0;

    // find Java home directory
    String javaHome = System.getProperty("java.home");
    String fileSeparator = System.getProperty("file.separator");
   
    // set quoting style (windows only can use quotes)
    String quote = windowsOS ? "\"" : "";
   
    // check if version is still good
    String jnlpPath = jnlp.substring(0, jnlp.lastIndexOf("
/") + 1);
    String requiredVersionFile = jnlpPath + "
RequiredWebstartRunner.version";
    try {
      // find remote version
      URL url = new URL(requiredVersionFile);
      URLConnection connection = url.openConnection();
      BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      String line = reader.readLine();
      int remoteVersion = Integer.parseInt(line);
     
      // check if still valid
      if (remoteVersion > localVersion) {
        // tell newer version available
        JOptionPane.showMessageDialog(null
            , "
A new version of the Aevum Obscurum game client is available!\n"
            + "
Please go to http://www.aevumobscurum.com for information and download.\n"
            + "\n"
            + "Your Installed Version: V" + localVersion + "\n"
            + "Required Version: V" + remoteVersion + "\n"
            + "\n"
            , "Aevum Obscurum: New Version Available."
            , JOptionPane.ERROR_MESSAGE);

        // need to redownload!
        System.out.println("Redownload of installer required. New version available");
      }
      else {
        // build list of commands
        String[] cmd = new String[2];
        if (macOSX) {
          cmd[0] = "javaws";
        }
        else {
          cmd[0] = quote + javaHome + fileSeparator + "bin" + fileSeparator + "javaws" + quote;
        }
        cmd[1] = jnlp;
       
        // set property!
        System.setProperty("runtime.start.method", "install4j");
        System.setProperty("runtime.start.version", "" + localVersion);
       
        // and execute command!
        try {
          Runtime.getRuntime().exec(cmd);
        }
        catch (IOException e) {
          System.err.println("Cannot start the webstart file (" + jnlp + "): " + e);
        }
      }
    }
    catch (IOException e) {
      // server down or file not found - connection cannot be established
      JOptionPane.showMessageDialog(null
          , "The connection to the Aevum Obscurum server could not be established.\n"
          + "Please try again later or go to http://www.aevumobscurum.com for further "
          + "information.\n"
          + "\n"
          + "We apologize for any inconvenience this might cause you.\n"
          + "\n"
          + "\n"
          , "Error Connecting to Aevum Obscurum Server"
          , JOptionPane.ERROR_MESSAGE);
     
      // output error to console
      System.err.println("IO exception (" + requiredVersionFile + "): " + e);
    }
  }
 
  /**
   * The main method which will be called.
   *
   * @param args  The arguments for the webstart runner.
   *              args[0] should be the location of the .jnlp file to run.
   *              args[1] the version of the installer.
   */

  public static void main(String[] args) {
    run(args[0], Integer.parseInt(args[1]));
  }
}


Offline Eliwood

Junior Devvie




Stencyl


« Reply #4 - Posted 2007-02-09 05:24:56 »

It turned out to be a variety of issues, but they all linked back to the fact that Linux and OS X don't like quotes in the command line, despite me using them fine in the shell scripts I provided for Linux users.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (37 views)
2014-12-15 09:26:44

Mr.CodeIt (30 views)
2014-12-14 19:50:38

BurntPizza (62 views)
2014-12-09 22:41:13

BurntPizza (99 views)
2014-12-08 04:46:31

JscottyBieshaar (59 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (77 views)
2014-11-29 21:32:03

toopeicgaming1999 (138 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (38 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!