Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Sending Command via StdinWrite to a jar / batch

$
0
0

Hey,
I am writing a WinGUI for the Bukkit Server. (Server Mod for the well known Minecraft game)
Its function should be, that you can easily issue commands and see the whole server log in the current console.
I will also add some other features, like an easy way to check all your plugin versions and maybe an auto-updater for them.
Starting the Server per batch or run has some limitations that just doesn't sit right with me.

Now I got so far that I can easily get all the output send to the Input-box on my Form with StdoutRead.
The problem is that I can't send any commands to the Server with StdinWrite.
If you could give me some pointers or even a fixed version of the script I would be very grateful.

MfG Moonwolf

PS: For everyone, who want to test the script for themselves; It is currently only set up for 64bit machines and the run command has to be rewritten for 32bit machines.

AutoIt         
  1. #include <ButtonConstants.au3>
  2. #include <EditConstants.au3>
  3. #include <GUIConstantsEx.au3>
  4. #include <WindowsConstants.au3>
  5. #include <Constants.au3>
  6. #include <Array.au3>
  7.  
  8. Opt("GUIOnEventMode", 1)
  9. $ServerWin = GUICreate("Bukkit Server Control v0.1", 1458, 691, 182, 114)
  10. GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose")
  11. $SerMen1 = GUICtrlCreateMenu("Server")
  12. $SerMen1Sub1 = GUICtrlCreateMenuItem("Save-All", $SerMen1)
  13. $SerMen1Sub2 = GUICtrlCreateMenuItem("Reload Plugins", $SerMen1)
  14. $SerMen1Sub3 = GUICtrlCreateMenuItem("Save + Quit", $SerMen1)
  15. $SerMen1Sub4 = GUICtrlCreateMenuItem("Quit", $SerMen1)
  16. $SerMen2 = GUICtrlCreateMenu("Help")
  17. $SerMen2Sub1 = GUICtrlCreateMenuItem("Check for Updates", $SerMen2)
  18. $SerMen2Sub2 = GUICtrlCreateMenuItem("About", $SerMen2)
  19. $ConsoleOut = GUICtrlCreateEdit("", 8, 8, 890, 441, BitOR($ES_AUTOHSCROLL,$ES_WANTRETURN,$ES_READONLY,$WS_HSCROLL,$WS_VSCROLL))
  20. GUICtrlSetState(-1, $GUI_DISABLE)
  21. $ConsoleIn = GUICtrlCreateInput("Input Command", 8, 450, 817, 21)
  22. $SendCmd = GUICtrlCreateButton("Send", 824, 449, 76, 22)
  23. GUICtrlSetOnEvent($SendCmd, "OnSend")
  24.  
  25. ;some debug stuff
  26. $debug = 0
  27. If ($debug == 1) Then
  28.    MsgBox(0,"debug","Scriptdir: " & '"' & @ScriptDir & '"' & @CRLF & "working dir: " & '"' & @WorkingDir & '"')
  29.    MsgBox(0,"debug", "OSarch: " & @OSArch)
  30.  
  31. ;Start the Bukkit Server
  32. ;Note: set @SW_SHOW to @SW_HIDE after debug!
  33. ;Note: add check for 32bit arch after StdinWrite has been resolved
  34. ;$Server = Run('Start.bat',@ScriptDir,@SW_Show,$STDIN_CHILD + $STDERR_MERGED)
  35. $Server = Run('"C:\Program Files\Java\jre7\bin\java.exe" -Xms1024M -Xmx1024M -jar "C:\Users\Moonwolf\Desktop\Craftbukkit Server\craftbukkit.jar"',@ScriptDir,@SW_Show,$STDIN_CHILD + $STDERR_MERGED)
  36.  
  37. ;Main Loop
  38.    ReadOut()
  39.  
  40. ;Write data to InputBox
  41. Func ReadOut()
  42.    While 1
  43.       GUICtrlSetData($ConsoleOut, StringAddCR(StdoutRead($Server)), 1)
  44.    WEnd
  45.  
  46. ;Send Command
  47. Func OnSend()
  48.    StdinWrite($Server,GUICtrlRead($ConsoleIn) & @CRLF)
  49.    If ($debug == 1) Then
  50.       MsgBox(0,"debug", "Sending: " & GUICtrlRead($ConsoleIn))
  51.    EndIf
  52.    GUICtrlSetData($ConsoleIn,"")
  53.  
  54. ;save exit
  55. Func OnClose($Server)
  56.    StdinWrite($Server,"stop" & @CRLF)
  57.    ; additional stop script for batch server
  58.    ;While ProcessExists($Server)
  59.    ;    Sleep(1000)
  60.    ;    StdinWrite($Server,"{ENTER}")
  61.    ;WEnd
  62.    Exit

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>