EpicKnarvik97
EpicKnarvik97

Reputation: 165

Autoit Java argument in run command through $chosen variable

I made a combo:

$Combo1 = GUICtrlCreateCombo("Java Memory", 24, 872, 145, 25, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "-Xmx1024M|-Xmx2048M|-Xmx3072M|-Xmx4096M")

Then I added something to read it:

$chosen = GUICtrlRead($Combo1)

Then I made a run command and put $chosen in it:

Run ("java -jar spigot-1.6.2-R0.1.jar " & $chosen, "E:\Spill\Alle spill\Minecraft\KnarCraft 2013")

When I don't choose an option in the drop down list, it starts. When I do, it comes a window that disappears instantly, but it shows all valid parameters so therefore something is wrong in the way it reads it. I think it has something to do with the - but I don't know how i should do it. I tried using a - and then the variable, but then it reads it as -$chosen instead of "-" + "choice in $chosen".

Upvotes: 1

Views: 913

Answers (1)

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

  • First off, the order of your java command line I believe is important, and so the -Xmx option should come after the "java" and before the "-jar" tokens.
  • Next, I wonder if you're trying to use too much memory. Have you considered testing this with smaller values?

For example:

$Combo1 = GUICtrlCreateCombo("Java Memory", 10, 10, 142, 25, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "-Xmx100M|-Xmx200M|-Xmx400M|-Xmx800M|-Xmx1024M|-Xmx2048M|-Xmx3072M|-Xmx4096M")

Then see if any of the smaller numbers work and if the larger numbers break the program.

My test program:

AutoIt program, MyFoo.au3:

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>

Example()

Func Example()
    Local $msg
    GUICreate("My GUI combo")  ; will create a dialog box that when displayed is centered

    $Combo1 = GUICtrlCreateCombo("Java Memory", 10, 10, 142, 25, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, "-Xmx100M|-Xmx200M|-Xmx400M|-Xmx800M|-Xmx1024M|-Xmx2048M|-Xmx3072M|-Xmx4096M")

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        If $msg = $Combo1 Then
            $chosen = GUICtrlRead($Combo1)
            $runString1 = "java " & $chosen & " -jar MyFoo.jar"
            $runString2 = "java -jar MyFoo.jar " & $chosen
            ConsoleWrite($runString1 & @CRLF)
            Run($runString1)
        EndIf

        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   

Java test program, MyAutoItFoo.java. Of course this was jar'd first:

import javax.swing.JOptionPane;

public class MyAutoItFoo {
   public static void main(String[] args) {
      long heapSize = Runtime.getRuntime().totalMemory();
      long heapMaxSize = Runtime.getRuntime().maxMemory();
      String heapString = String.format("Heap Size = %H; Max Heap = %H", 
            heapSize, heapMaxSize);
      System.out.println(heapString);
      JOptionPane.showMessageDialog(null, heapString);
   }
}

Upvotes: 1

Related Questions