Jump to content
Sign in to follow this  

Sending Command via StdinWrite to a jar / batch

Recommended Posts

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.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <Array.au3>

#Region ### START Koda GUI section ### Form=E:\Program Files (SA)\Koda GUIDesigner\Forms\ServerWin.kxf
Opt("GUIOnEventMode", 1)
$ServerWin = GUICreate("Bukkit Server Control v0.1", 1458, 691, 182, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose")
$SerMen1 = GUICtrlCreateMenu("Server")
$SerMen1Sub1 = GUICtrlCreateMenuItem("Save-All", $SerMen1)
$SerMen1Sub2 = GUICtrlCreateMenuItem("Reload Plugins", $SerMen1)
$SerMen1Sub3 = GUICtrlCreateMenuItem("Save + Quit", $SerMen1)
$SerMen1Sub4 = GUICtrlCreateMenuItem("Quit", $SerMen1)
$SerMen2 = GUICtrlCreateMenu("Help")
$SerMen2Sub1 = GUICtrlCreateMenuItem("Check for Updates", $SerMen2)
$SerMen2Sub2 = GUICtrlCreateMenuItem("About", $SerMen2)
GUICtrlSetData(-1, "")
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetCursor (-1, 5)
$ConsoleIn = GUICtrlCreateInput("Input Command", 8, 450, 817, 21)
$SendCmd = GUICtrlCreateButton("Send", 824, 449, 76, 22)
GUICtrlSetOnEvent($SendCmd, "OnSend")
#EndRegion ### END Koda GUI section ###

;some debug stuff
$debug = 0
If ($debug == 1) Then
   MsgBox(0,"debug","Scriptdir: " & '"' & @ScriptDir & '"' & @CRLF & "working dir: " & '"' & @WorkingDir & '"')
   MsgBox(0,"debug", "OSarch: " & @OSArch)

;Start the Bukkit Server
;Note: set @SW_SHOW to @SW_HIDE after debug!
;Note: add check for 32bit arch after StdinWrite has been resolved
;$Server = Run('Start.bat',@ScriptDir,@SW_Show,$STDIN_CHILD + $STDERR_MERGED)
$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)

;Main Loop
While 1

;Write data to InputBox
Func ReadOut()
   While 1
      GUICtrlSetData($ConsoleOut, StringAddCR(StdoutRead($Server)), 1)
      If @error Then ExitLoop

;Send Command
Func OnSend()
   StdinWrite($Server,GUICtrlRead($ConsoleIn) & @CRLF)
   If ($debug == 1) Then
      MsgBox(0,"debug", "Sending: " & GUICtrlRead($ConsoleIn))

;save exit
Func OnClose($Server)
   StdinWrite($Server,"stop" & @CRLF)
   ; additional stop script for batch server
   ;While ProcessExists($Server)
   ;    Sleep(1000)
   ;    StdinWrite($Server,"{ENTER}")

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...