Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Suspend Script while running ext prog (w/o WAITFOR)

Status
Not open for further replies.

GeoffKelly

Technical User
Dec 4, 2002
3
US
Does anyone know if it is possible to suspend a script from continuing until an external program (launched by script) is closed? Unfortunately, both the DOS program and Windows program I will be spawning don't output any information back on the COM ports I will be talking to in my script so I will not be able to use WAITFOR (at least no based on what I have read).

The ideal method would be to launch the program and use something like CreateProcess and WaitForSingleObject, but I don't know of a way in ASPECT to get the ThreadID and ProcessID.

Is there a way in ASPECT to declare functions from Windows DLLs? This would allow me to declare the CreateProcess and WaitForSingleObject functions I need.

Thanks,
Geoff
 
If your script is launching the programs via the run command, you can get the task ID of the app and then use the taskexists command to determine if the app is still running or not. If you look at the discussion of taskexists in the ASPECT help file, it has an example script that shows how to launch notepad and then loop until notepad is closed. I don't know off the top of my head if this will work for your DOS application or not.
aspect@aspectscripting.com
 
Thank you for your response. It looks as if this should work. Since I am new to ASPECT I kinda overthought the problem - didn't know about TASKEXISTS.

I wrote a quick sample script (below) to test whether this will work for the DOS app and it works, although the TaskID is set to "(null)".

***********************************************************

PROC MAIN

INTEGER TaskID

RUN "CMD.EXE" TaskID

WHILE TASKEXISTS TaskID
TERMMSG "Waiting for DOS window (%s) to close...`r`n" TaskID
YIELD
ENDWHILE

TERMMSG "DOS Window (%s) has closed." TaskID

ENDPROC

***********************************************************

Output:
Waiting for DOS Window ((null)) to close...
.
.
.
DOS Window ((null)) has closed.
 
Silly me! TaskID is "(null)" because I used the wrong substitution operator (%s instead of %i). The corrected code works perfect!

***********************************************************

PROC MAIN

INTEGER TaskID

RUN "CMD.EXE" TaskID

WHILE TASKEXISTS TaskID
TERMMSG "Waiting for DOS window (%i) to close...`r`n" TaskID
YIELD
ENDWHILE

TERMMSG "DOS Window (%i) has closed." TaskID

ENDPROC

***********************************************************

Output:
Waiting for DOS Window (####) to close...
.
.
.
DOS Window (####) has closed.
 
As for your question about accessing some Windows API calls through ASPECT, it can't be done as-is. However, you can write an ASPECT-callable DLL that can be loaded from your script. I've never done this myself, but the developer of ASPECT gave me a template that I've made available on my site. I've never written an ASPECT-compatible DLL myself, so that's all the information I can offer about that. You can grab the ZIP file at aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top