add SYNCHRONOUS behaviour to RunProgram??

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Fangbeast.

Anyone know how to add some sort of SYNCHRONOUS behaviour to RunProgram? The program I wrote will be used on so many different speed systems that my shelling out to external programs could well stuff up the rest of the code.

Using DELAY is not a good idea because it doesn't take into account different CPU speeds.

If I add the RunProgram routine to a separate procedure, would this have a Synchronous effect??

Regards

Fangles
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
Anyone know how to add some sort of SYNCHRONOUS behaviour to RunProgram?
Yes, you can do it many ways depending on what you need. For example, here's a way to launch the Windows calculator and halt program execution until you close the calc:

runprogram("calc.exe","",0)
delay(1000) ; Just to give calc some time to open :)
repeat : r=findwindow_(0,"Calculator") : until r=0
messagerequester("done!","calc exited",0)
end
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.
[runprogram("calc.exe","",0)
delay(1000) ; Just to give calc some time to open :)
repeat : r=findwindow_(0,"Calculator") : until r=0
messagerequester("done!","calc exited",0)
end
This don't work on non-english Windows, think about it.. Here it's "Calculatrice" :). I've added the possibility to run an app scynchronously and to hide it if necessary to RunProgram()... For the next release


Edited by - fred on 19 October 2001 16:13:32
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
This don't work on non-english Windows, think about it.. Here it's "Calculatrice" :).
It was just an example to show one way of doing it. :) But I'm glad to see that you've added a syncronous version of RunProgram to the next release -- thanks for that!
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
Fred, I hope I told you lately, you are a legend
Yes, Fred is DA MAN! :) Fred's willingness to help is one of the main reasons I stopped using Visual Basic (what a waste of $900!) and paid for PureBasic.

BTW, Fangbeast, what part of Oz are you from? I'm in Sydney.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
I've added the possibility to run an app scynchronously and to hide it if necessary to RunProgram()...
Is there a way to run an external program but still continue your PureBasic app until the external program ends? What I need to do is launch an external app, but then keep my PureBasic program doing things until the other app closes. The other app uses different window captions so I can't check for their existence... I guess what I need is something like this:

Code: Select all

RunProgram("otherapp.exe","",1) ; Run app and tell PureBasic to know when it's closed.
Repeat
  ; Do my other stuff here until other app closes...
Until OtherAppCloses
End
PB - Registered PureBasic Coder

Edited by - PB on 29 November 2001 03:51:36
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wavemaker.

Well, the next code does NOT work, but it should XXDDDDD:

Code: Select all

si.STARTUPINFO
pi.PROCESS_INFORMATION
#STILL_ACTIVE = $103

GetStartupInfo_(@si)
appname.s = "C:\Windows\Notepad.exe"

; This should work if PB accepted 10 parameters for CreateProcess_, and not 13, as it does.

If CreateProcess_(@appname, 0, 0, 0, 0, 0, 0, 0, @si, @pi)
  ExitCode = #STILL_ACTIVE
  While ExitCode = #STILL_ACTIVE ; Here goes your program loop, exits when you close Notepad
    GetExitCodeProcess_(pi\hProcess, @ExitCode)
  Wend
  MessageRequester("Message",appname + " terminated.",0)
EndIf
Hope it helps, bye,

Juan Calderón Alonso
Registered user

Edited by - wavemaker on 29 November 2001 09:11:29
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Use the new Thread library (v2.70 available) and when the program end set the variable to on:

Code: Select all

Procedure prog(a)
  Shared IsFinished
  RunProgram(...,1)
  IsFinished = 1
endprocedure

Repeat
  ...
Until IsFinished = 1
Fred - AlphaSND
Post Reply