Java Console Output and ReadProgramString()

Just starting out? Need help? Post your questions and find answers here.
deano1987
User
User
Posts: 19
Joined: Thu Jul 30, 2009 11:39 pm
Location: england, cannock, west midlands

Java Console Output and ReadProgramString()

Post 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?
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Java Console Output and ReadProgramString()

Post 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()
----

R Tape loading error, 0:1
deano1987
User
User
Posts: 19
Joined: Thu Jul 30, 2009 11:39 pm
Location: england, cannock, west midlands

Re: Java Console Output and ReadProgramString()

Post 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?
Sirius-2337
User
User
Posts: 59
Joined: Sat May 14, 2011 10:39 am

Re: Java Console Output and ReadProgramString()

Post 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?
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Java Console Output and ReadProgramString()

Post 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.
----

R Tape loading error, 0:1
Post Reply