Page 1 of 1

Help for RunProgram ()

Posted: Sat Sep 16, 2017 6:11 pm
by PremierePRO
I need to start an external program via RunProgram (), this program is launched between Repeat and ForEver commands ... how can I prevent the software from being launched infinitely?

Repeat

RunProgram ()

Forever

Re: Help for RunProgram ()

Posted: Sat Sep 16, 2017 6:24 pm
by infratec
Hi,

you can use IsProgram() or ProgramRunning(), depending on what you need.

Bernd

Re: Help for RunProgram ()

Posted: Mon Sep 18, 2017 8:27 am
by Dude
Like this:

Code: Select all

Repeat
  RunProgram("app.exe","","",#PB_Program_Wait)
  Delay(1000)
ForEver
Warning: I put Delay(1000) there as a failsafe, because if you forget the #PB_Program_Wait flag then the constant launching will crash your PC. The delay of one second allows you to kill your app to stop it launching any further executables.

Re: Help for RunProgram ()

Posted: Mon Sep 18, 2017 9:25 am
by Marc56us
I need to start an external program via RunProgram (), this program is launched between Repeat and ForEver commands ... how can I prevent the software from being launched infinitely?
A way

Code: Select all

EnableExplicit

Enumeration 
     #Win  
     #B_Run
     #B_Quit
EndEnumeration

Global ID_Prog

OpenWindow(#Win, 0, 0, 640, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StickyWindow(#Win, 1)
ButtonGadget(#B_Run,  WindowWidth(#Win) - 200, WindowHeight(#Win) - 40, 80, 25, "Run")
ButtonGadget(#B_Quit, WindowWidth(#Win) - 100, WindowHeight(#Win) - 40, 80, 25, "Quit")



Procedure Close_All()
     If IsProgram(ID_Prog) And ProgramRunning(ID_Prog)
          If MessageRequester("Sub program is running", 
                              "Should I close it automatically (without checking!)",
                              #PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes
               KillProgram(ID_Prog)
               CloseProgram(ID_Prog)
               End
          Else
               ProcedureReturn 
          EndIf
     EndIf
     End
EndProcedure



Repeat
     Select WaitWindowEvent()
               
          Case #PB_Event_CloseWindow
               Close_All()
               
          Case #PB_Event_Gadget
               Select EventGadget()
                         
                    Case #B_Run
                         If IsProgram(ID_Prog) And ProgramRunning(ID_Prog)
                              MessageRequester("Sorry", "The program is still running. Close it first")  
                         Else
                              ID_Prog = RunProgram("Notepad", "", "", #PB_Program_Open | #PB_Program_Read)
                         EndIf   
                         
                    Case #B_Quit
                         Close_All()   
                         
               EndSelect
     EndSelect
ForEver

End