Anyway get identify of RunProgram if #PB_Program_Wait used?

Just starting out? Need help? Post your questions and find answers here.
sec
Enthusiast
Enthusiast
Posts: 790
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Anyway get identify of RunProgram if #PB_Program_Wait used?

Post by sec »

Anyway get identify of RunProgram if #PB_Program_Wait used?

Code: Select all

Global startTime.i, notepad.i
Procedure activityMonitor(*dummy)
  Repeat
    If ElapsedMilliseconds() - startTime > (5 * 1000) *1 ; 5 seconds
      Debug "5 seconds"      
      KillProgram(notepad)
    EndIf 
    Delay(250)
  ForEver
EndProcedure
monitoringThread = CreateThread(@activityMonitor(), 0)
startTime.i = ElapsedMilliseconds()

notepad = RunProgram("C:\Windows\System32\notepad.exe","","",#PB_Program_Wait)

; do my other stuffs 
error: [ERROR] The specified 'Program' is null.

Thanks
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

Re: Anyway get identify of RunProgram if #PB_Program_Wait us

Post by Crusiatus Black »

You're waiting for notepad.exe to finish executing, so the notepad variable will never be defined before notepad.exe closes.

Code: Select all

Global startTime.i, notepad.i
Procedure activityMonitor(*dummy)
  Repeat
    If ElapsedMilliseconds() - startTime > (5 * 1000) *1 ; 5 seconds
      Debug "5 seconds"      
      KillProgram(notepad)
      ProcedureReturn
    EndIf 
    Delay(250)
  ForEver
EndProcedure
monitoringThread = CreateThread(@activityMonitor(), 0)
startTime.i = ElapsedMilliseconds()

notepad = RunProgram("C:\Windows\System32\notepad.exe","","", #PB_Program_Open)

; do my other stuffs

; this could be an event loop for a Window, or some other task that lasts longer than 5 seconds. 
; you could have this loop below at the end of your program, so that it still waits for notepad.exe to finish
While (IsProgram(notepad) and ProgramRunning(notepad)) 
  Delay(1)
Wend 
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
sec
Enthusiast
Enthusiast
Posts: 790
Joined: Sat Aug 09, 2003 3:13 am
Location: 90-61-92 // EU or ASIA
Contact:

Re: Anyway get identify of RunProgram if #PB_Program_Wait us

Post by sec »

Crusiatus Black wrote:You're waiting for notepad.exe to finish executing, so the notepad variable will never be defined before notepad.exe closes.

Code: Select all

Global startTime.i, notepad.i
Procedure activityMonitor(*dummy)
  Repeat
    If ElapsedMilliseconds() - startTime > (5 * 1000) *1 ; 5 seconds
      Debug "5 seconds"      
      KillProgram(notepad)
      ProcedureReturn
    EndIf 
    Delay(250)
  ForEver
EndProcedure
monitoringThread = CreateThread(@activityMonitor(), 0)
startTime.i = ElapsedMilliseconds()

notepad = RunProgram("C:\Windows\System32\notepad.exe","","", #PB_Program_Open)

; do my other stuffs

; this could be an event loop for a Window, or some other task that lasts longer than 5 seconds. 
; you could have this loop below at the end of your program, so that it still waits for notepad.exe to finish
While (IsProgram(notepad) and ProgramRunning(notepad)) 
  Delay(1)
Wend 
Nice code. Thanks!
Post Reply