Programrunning doesn't work with batch programs

Just starting out? Need help? Post your questions and find answers here.
artnat
User
User
Posts: 12
Joined: Sun Nov 10, 2024 3:34 pm

Programrunning doesn't work with batch programs

Post by artnat »

If I start a batch file with RunProgram, a valid 1 is returned, but to find the end condition by ProgramRunning does not work. The error message is "The specified program is not valid". That is not very astonishing, since the batchfile starts another program, and what I want to find out is, when this program finishes, and not the batch itself. But does anybody know, how to get an end condition for the program, which is started by the batch file?
infratec
Always Here
Always Here
Posts: 7575
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Programrunning doesn't work with batch programs

Post by infratec »

No code .... no help.

How should we know what you have done exactly?
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Programrunning doesn't work with batch programs

Post by TI-994A »

artnat wrote: Sun Dec 01, 2024 4:30 pm...how to get an end condition for the program, which is started by the batch file?

Hi @artnat. If you know the name of the program, you could try this approach. This example tracks Notepad, so simply start and stop Notepad to see the progress:

Code: Select all

;
; originally posted in October 2012
; https://www.purebasic.fr/english/viewtopic.php?p=394076#p394076
; 

Procedure.i FindWindowTitle(tSearch.s)
  Protected hWnd.i, tWnd.s
  hWnd = GetWindow_(GetDesktopWindow_(), #GW_CHILD)
  While hWnd
    tWnd = Space(GetWindowTextLength_(hWnd) + 2)
    GetWindowText_(hWnd, tWnd, Len(tWnd))
    If FindString(LCase(tWnd), LCase(tSearch))
      ProcedureReturn 1
    EndIf
    hWnd = GetWindow_(hWnd, #GW_HWNDNEXT)
  Wend
  ProcedureReturn 0
EndProcedure

win = OpenWindow(#PB_Any, 0, 0, 400, 200, "Program Monitor (Windows only)",
                 #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
status = TextGadget(#PB_Any, 0, 80, 400, 30, "", #PB_Text_Center)
AddWindowTimer(win, 0, 1000)

Repeat
  event = WaitWindowEvent()  
  Select event
      
    Case #PB_Event_Timer
      If FindWindowTitle("Notepad")
        SetGadgetText(status, "Notepad is running...")
      Else        
        SetGadgetText(status, "Notepad is currently not running.")               
      EndIf
      
    Case #PB_Event_CloseWindow
      appQuit = #True
      
  EndSelect  
Until appQuit
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
artnat
User
User
Posts: 12
Joined: Sun Nov 10, 2024 3:34 pm

Re: Programrunning doesn't work with batch programs

Post by artnat »

I found a way, to start the program itself with the batchfile as parameter. The program (freefilesync) runs fine, and the handle is 1, but I still get the error message "The specified "program" is not valid."

Code: Select all

handle.i=RunProgram("FreeFileSync.exe", "C:\Users\hd\OneDrive\Documents\prog\purebasic\dsich_neu\BatchRun.ffs_batch", "C:\Program Files\FreeFileSync\")
Debug handle

While ProgramRunning(handle)
  Debug handle
  Delay (1000)
Wend
User avatar
TI-994A
Addict
Addict
Posts: 2698
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Programrunning doesn't work with batch programs

Post by TI-994A »

artnat wrote: Sun Dec 01, 2024 6:06 pm I found a way, to start the program itself with the batchfile as parameter. The program (freefilesync) runs fine, and the handle is 1, but I still get the error message "The specified "program" is not valid."

Code: Select all

handle.i=RunProgram("FreeFileSync.exe", "C:\Users\hd\OneDrive\Documents\prog\purebasic\dsich_neu\BatchRun.ffs_batch", "C:\Program Files\FreeFileSync\")
Debug handle

While ProgramRunning(handle)
  Debug handle
  Delay (1000)
Wend

To get a valid handle, you might need to add the #PB_Program_Open flag, like so:

Code: Select all

handle.i=RunProgram("FreeFileSync.exe", "C:\Users\hd\OneDrive\Documents\prog\purebasic\dsich_neu\BatchRun.ffs_batch", "C:\Program Files\FreeFileSync\", #PB_Program_Open)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply