Help for RunProgram ()

Just starting out? Need help? Post your questions and find answers here.
PremierePRO
User
User
Posts: 28
Joined: Tue Apr 16, 2013 10:31 am

Help for RunProgram ()

Post 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
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Help for RunProgram ()

Post by infratec »

Hi,

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

Bernd
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Help for RunProgram ()

Post 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.
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: Help for RunProgram ()

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