Page 1 of 1

Java Console Output and ReadProgramString()

Posted: Sun May 22, 2011 1:46 pm
by deano1987
Hey guys, I've searched and searched for an answer to this but none of the topics I've come across have had an answer.

Basically I'm running a minecraft server from a PureBasic application and reading the programs output aswel as writing to the programs output, everything works fine apart from output, some output comes through and other output (the important stuff like player has connected or said stuff) does not get returned. Even more strangely, this information seems to drop straight into my PureBasic applications Console window. What gives!?!

this is how i run the program:

Code: Select all

Minecraft = RunProgram("java", "-jar minecraft_server.jar nogui" ,"C:\Users\Deano\Desktop\Minecraft\Server", #PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Error|#PB_Program_Hide)
This is how i grab its output:

Code: Select all

If ProgramRunning(Minecraft)
      MinecraftTimer=MinecraftTimer+1
  
      If AvailableProgramOutput(Minecraft)
          WriteMinecraftLog(ReadProgramString(Minecraft))
      EndIf
    EndIf
Is there anyone who can help me please?

Re: Java Console Output and ReadProgramString()

Posted: Mon May 23, 2011 12:52 am
by em_uk
Hi,

I couldn't get the minecraft server working, but I never have a problem reading a programs output with this :

Code: Select all

OpenConsole()

Procedure RunCom(cmd$,arg$,path$,extra=0)
  
  result=-245678
  
  prgid=RunProgram(cmd$,arg$, path$,  #PB_Program_Read|#PB_Program_Open|#PB_Program_Write|#PB_Program_Error)
  
  If prgid
    Repeat  
      
      While AvailableProgramOutput(prgid)
        in$=(ReadProgramString(prgid))
        PrintN(in$)
      Wend
      
      Delay(10) 
      err$=ReadProgramError(Prgid)
      
      If err$
        Debug err$
      EndIf
      
    Until ProgramRunning(prgid)=0
    result=ProgramExitCode(prgid)
  EndIf
  
  ProcedureReturn result
  
EndProcedure

result=RunCom("cmd.exe", "/c dir /s f:\*temp* /b","")

Debug "Exit Code : " + Str(result)

CloseConsole()

Re: Java Console Output and ReadProgramString()

Posted: Thu Jun 02, 2011 11:28 am
by deano1987
Tried this out and its still only giving me the starting response and nothing else.

I think it's got something to do with the fact it's not sending a proper line end and PureBasic isn't reading it, is there another method I could use?

Re: Java Console Output and ReadProgramString()

Posted: Thu Jun 02, 2011 11:41 am
by Sirius-2337
The Code works fine with my Minecraft Server but most Messages come as ProgramError so you have to read them with ReadProgrammError() as in the Code above.
Do you have your debugger enabled?

Re: Java Console Output and ReadProgramString()

Posted: Thu Jun 02, 2011 8:30 pm
by em_uk
deano1987 wrote:Tried this out and its still only giving me the starting response and nothing else.

I think it's got something to do with the fact it's not sending a proper line end and PureBasic isn't reading it, is there another method I could use?
I assure you the method I posted should give you everything you need, make sure the debugger is enabled, as in my example the StdError messages will be displayed there.