2 Questions about RunProgram

Just starting out? Need help? Post your questions and find answers here.
porfirio
Enthusiast
Enthusiast
Posts: 111
Joined: Mon Nov 15, 2004 11:00 pm
Location: portugal

2 Questions about RunProgram

Post by porfirio »

Hi all

The first question is:

Why this code gives right output

Code: Select all

OpenConsole()
PrintN("Running Java")
JavaP = RunProgram("java", "-version", "",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)

If IsProgram(JavaP) 
  While ProgramRunning(JavaP)
    PrintN(ReadProgramString(JavaP))
  Wend
  PrintN("Exitcode: " + Str(ProgramExitCode(JavaP)))  
Else
  PrintN("not a program")
EndIf
Input()
CloseConsole()
and this one dont:

Code: Select all

Debug "Running Java"
JavaP = RunProgram("java", "-version", "",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)

If IsProgram(JavaP) 
  While ProgramRunning(JavaP)
    Debug ReadProgramString(JavaP)
  Wend
  Debug "Exitcode: " + Str(ProgramExitCode(JavaP)) 
Else
  Debug "not a program"
EndIf
And the second question is:
How to not show java process or atleast, when myprocess is killed java is killed too?

As you may notice i am doing a small Java runner.

There's tones of them but i want to do one for my own use, with my own options and i want to be able to compile\run it on Linux\Mac\Windows
I want that if user is runing on windows ( alot noob's ), they can just kill the program in the TaskManager, so hiding the process is just need for windows, on mac\linux i will just run Java

If someone can help me i appreciate :)
Forgive-me for my english, i'm portuguese!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: 2 Questions about RunProgram

Post by Trond »

porfirio wrote:Hi all

The first question is:

Why this code gives right output

and this one dont:
Did you turn on the debugger and read the manual description of Debug?
porfirio
Enthusiast
Enthusiast
Posts: 111
Joined: Mon Nov 15, 2004 11:00 pm
Location: portugal

Re: 2 Questions about RunProgram

Post by porfirio »

Trond wrote:
porfirio wrote:Hi all

The first question is:

Why this code gives right output

and this one dont:
Did you turn on the debugger and read the manual description of Debug?
Yeah
either i get

Exitcode: 0
Forgive-me for my english, i'm portuguese!
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

You do realize that when you create an executable the debugger is always disabled?
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

it is? I thought there was an embedded debugger...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Yes, but when you use the create executable menu item from the IDE the debugger is always disabled.
Character
Enthusiast
Enthusiast
Posts: 337
Joined: Mon Aug 07, 2006 3:51 pm
Location: Netherlands

Post by Character »

this way I get an Exitcode of 1

Code: Select all

Debug "Running Java" 
JavaP = RunProgram("java", "-showversion", "",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read) 

If IsProgram(JavaP) 
  While ProgramRunning(JavaP) 
    Debug ReadProgramString(JavaP) 
  Wend 
  Debug "Exitcode: " + Str(ProgramExitCode(JavaP)) 
Else 
  Debug "not a program" 
EndIf 
now without the helptext crap (displayed on my machine instead of the 'version text' when called through a console..)

Code: Select all

Debug "Running Java" 
JavaP = RunProgram("java", "-showversion>dump.txt", "",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read) 

If IsProgram(JavaP) 
  While ProgramRunning(JavaP) 
    Debug ReadProgramString(JavaP) 
  Wend 
  Debug "Exitcode: " + Str(ProgramExitCode(JavaP)) 
Else 
  Debug "not a program" 
EndIf 
all works in a console() but when using the debugger the java thing is already closed for ages when you start purebasing with it
when used '-showversion' the java thing halts execution but only displays the correct version in a console again, not in the debugger....
?
(I'm lost... )
Cessante causa cessat effectus
porfirio
Enthusiast
Enthusiast
Posts: 111
Joined: Mon Nov 15, 2004 11:00 pm
Location: portugal

Post by porfirio »

If i run java with no argument, it works and display all the help thing on the debugger

If i put any java file to be runned or a jar or something, it shows the output too

It just dont show the output with -version parameter lol

Very wheird...

Edit:

either :

Code: Select all

Debug "Running Java"
JavaP = RunProgram("cmd", "/r java -version", "",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)

If IsProgram(JavaP)
  While ProgramRunning(JavaP)
    Debug ReadProgramString(JavaP)
  Wend
  Debug "Exitcode: " + Str(ProgramExitCode(JavaP))
Else
  Debug "not a program"
EndIf 
Dont give the output too again if i dont put -version it displays java help

Edit again:

Theres something wrong with java.exe lol

java -showversion>out.txt

Get all java help shit on the txt and the version printed on the window!!

Oh god looks like i have to give up :S
Forgive-me for my english, i'm portuguese!
porfirio
Enthusiast
Enthusiast
Posts: 111
Joined: Mon Nov 15, 2004 11:00 pm
Location: portugal

Post by porfirio »

Just found a quick solution for get the jre version

Created a small class file that will be included on the exe using this code
javac Test.java

Code: Select all

public class Test{
   public static void main(String[] args){
      System.out.println(System.getProperty("java.vm.version"));
   }
}
then i have this code on my app

Code: Select all

Procedure TestJava(v.s)
  JavaP = RunProgram("java", "Test", "",#PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
  If IsProgram(JavaP) 
    res.s=ReadProgramString(JavaP)
    res=Left(res,5)
    If Val(StringField(res,1,"."))>=Val(StringField(v,1,"."))
      If Val(StringField(res,2,"."))>=Val(StringField(v,2,"."))
        If Val(StringField(res,3,"."))>=Val(StringField(v,3,"."))
          ProcedureReturn #True
        EndIf 
      EndIf 
    EndIf 
    ProcedureReturn #False
  Else
    ProcedureReturn #False
  EndIf
  ProcedureReturn #False
EndProcedure

If TestJava("1.6.0")
  MessageRequester("Java Test","You have a good java version")
Else
  Select MessageRequester("Java Tester", "You dont have Java, or your java Version is outdated" + Chr(10) + "Want to go to Java Website to ge the lastest one?", #MB_YESNO|#MB_ICONQUESTION)
    Case #IDYES
      RunProgram("http://java.com/")
  EndSelect
EndIf
Of course that this will be more worked
Thanks in the same way guy's :)
Forgive-me for my english, i'm portuguese!
Post Reply