It is currently Thu Sep 09, 2010 8:37 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to check when an external program has finished?
PostPosted: Wed May 28, 2008 8:59 am 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 1284
I just try to compress quite a lot programs with upx now (for usage on an USB stick etc.)

So I just programmed a tiny tool, which just takes the command line and starts the upx.exe for each parameter in a minimized window.
It would be fine to have a status window where I can see all files which are going to be compressed and when they have finished. Does anyone have a (simple) idea for doing that?

Thanks,
Michael


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 9:09 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat Apr 26, 2003 4:56 pm
Posts: 1042
Location: 57.1604N, 2.1345W
Assuming you are using RunProgram() then you should also therefore be able to use ProgramRunning() to see if UPX is still running.

_________________
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB4.40)


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 9:21 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Sat May 17, 2003 11:31 am
Posts: 5220
I found a few cases where that would not work, as the app would be launching another app which was not in any way related to the first app as far as I could see.

Let's hope UPX behaves better :-)

_________________
My ambition in life: Total World Domination! My weapons of choice: CodeCaddy and The PureBasic Survival Guide
( PB4.4x XPpro SP3 Dell XPS710 Intel Q6600 nForce 5 NVidia 8800GTX )


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 10:00 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1032
Location: Pas-de-Calais, France
Not a really beautiful code, but should work
Code:
#PROCESS32LIB = 9999

Global NewList Process32.PROCESSENTRY32 () ;global=lame

;********************************************************************************************************
;>= Program name
;=> Program name without path
Procedure.s exe_name(name.s)

  u = Len(name)
  i = u + 1

  While Mid(name, i, 1) <> "\" And i>0
    i-1
  Wend

  ProcedureReturn Right(name,u-i)

EndProcedure

;********************************************************************************************************
;=> Active processus list in Process32 global list
Procedure.l get_process_list()

  ClearList(Process32 ())
 
  If OpenLibrary (#PROCESS32LIB, "kernel32.dll")

      snap = CallFunction (#PROCESS32LIB, "CreateToolhelp32Snapshot", #TH32CS_SNAPPROCESS, 0)

      If snap

          Define.PROCESSENTRY32 Proc32
          Proc32\dwSize = SizeOf (PROCESSENTRY32)
         
          If CallFunction (#PROCESS32LIB, "Process32First", snap, @Proc32)

              AddElement (Process32())
              CopyMemory (@Proc32, @Process32(), SizeOf (PROCESSENTRY32))
             
              While CallFunction (#PROCESS32LIB, "Process32Next", snap, @Proc32)
                  AddElement (Process32 ())
                  CopyMemory (@Proc32, @Process32(), SizeOf(PROCESSENTRY32))
              Wend
             
          EndIf   
          CloseHandle_ (snap)
     
      EndIf

      CloseLibrary (#PROCESS32LIB)
      ProcedureReturn #True

  Else

    ProcedureReturn #False

  EndIf

EndProcedure


;********************************************************************************************************
;Wait for the end of a program
; >= Program's name
Procedure.s wait_external_prog( name.s )

  ;Wait 'til program is in the task list

  setup=#False

  Repeat

    ;dd = WindowEvent()

    ;If dd = 0
      Delay(1000)
    ;EndIf

    If get_process_list() = #False
      Break
    EndIf

    ForEach Process32()
     
      a$ = LCase(PeekS (@Process32()\szExeFile))

      Debug a$

      If exe_name(a$) = name
        setup = #True
      EndIf

    Next

  Until setup=#True

  ;Wait 'til its end
  Repeat

    ;dd=WindowEvent()

    ;If dd = 0
      Delay(1000)
    ;EndIf

    setup = #False

    If get_process_list() = #False
      Break
    EndIf

    ForEach Process32()

      a$=LCase(PeekS (@Process32 ()\szExeFile))

      Debug a$

      If exe_name(a$)=name
        setup=#True
      EndIf

    Next

  Until setup=#False

EndProcedure

RunProgram("c:\windows\notepad.exe")
wait_external_prog( "notepad.exe" )


See also ProgramRunning() command with RunProgram().

_________________
BGames team ~> http://www.b-software.fr
Bobble Puzzle ~> http://djes.free.fr


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Google Adsense [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye