Bat File How to Wait for One Program to Finish Before Continuing
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Contact US
Thanks. We have received your request and will respond promptly.
Log In
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips Forums!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts - Keyword Search
- One-Click Access To Your
Favorite Forums - Automated Signatures
On Your Posts - Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Posting Guidelines
Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Students Click Here
How do you WAIT for a program or script to finish
- Forum
- Search
- FAQs
- Links
- MVPs
How do you WAIT for a program or script to finishHow do you WAIT for a program or script to finish(OP) I have programs that run small DOS batch files and/or small VB scripts and I need to wait for these to finish before the VFP script continues. I can put times to wait but the problem is that each script takes a different amount of time (some alot of time). Is there any way I can let the VFP program know it is finished so it can continue? Red Flag SubmittedThank you for helping keep Tek-Tips Forums free from inappropriate posts. |
Join | Advertise
Copyright © 1998-2022 engineering.com, Inc. All rights reserved.
Unauthorized reproduction or linking forbidden without expressed written permission. Registration on or use of this site constitutes acceptance of our Privacy Policy.
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
-
Talk To Other Members - Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close
Source: https://www.tek-tips.com/viewthread.cfm?qid=850950
RE: How do you WAIT for a program or script to finish
If the program(s) create a file, you can tell vfp to look for that file, and keep doing so until a (defined by you) timeout, or until the file appears with a time stamp later than when the program started. You'd use adir() in a DO WHILE loop.
There may be some other tricks if you could be more specific about the nature of these other programs, the OS, the user rights level, and the VFP version.
Brian
RE: How do you WAIT for a program or script to finish
greggb
If you use an appropriate WSH script or the WinAPI call CreateProcess(), you can ensure that control does not return to VFP until the external process is complete.
However, that does not necessarily mean that a file(s) created by the external process either exists or is complete.
As baltman suggests ADIR() in a DO WHILE loop will indicate the existence or otherwise of a file..
If you want to build in error trapping try the following code for the existence of a file. The value of the field USER.timeout can be set by the user in relation to the specification of their PC - shorter for state of the art hardware and longer for legacy hardware.
CODE
lnSeconds = SECONDS()
DO WHILE .T.
IF SECONDS() > lnSeconds + USER.timeout
llTimedOut = .T.
EXIT
ENDI
IF ADIR(laTemp,[C:\temp\output.txt]) = 1
EXIT
ELSE
INKEY(0.5)
ENDI
ENDDO
IF llTimedOut
MESSAGEBOX([Error - file does not exist!])
ENDI
The existence of a file does not necessarily mean the file is complete so you can determine that by attempting to open it with FOPEN()
CODE
lnSeconds = SECONDS()
DO WHILE .T.
IF SECONDS() > lnSeconds + USER.timeout
llTimedOut = .T.
EXIT
ENDI
lnOpen = FOPEN([C:\temp\output.txt],0)
IF lnNo = -1
FCLOSE(lnOpen)
ELSE
FCLOSE(lnOpen)
EXIT
ENDI
ENDDO
IF llTimedOut
MESSAGEBOX([Error - file cannot be opened!])
ENDI
Chris
PDFcommandertm.com
PDFcommandertm.co.uk
RE: How do you WAIT for a program or script to finish
HI
loShell = CREATEOBJECT("wscript.shell")
lcCmd = GETENV("ComSpec") + [ /C ]
lcBatCmd = lcCmd + [myBatch Command WITH parameters]
** example ..
** lcBatCmd = lcCmd + [CABARC -o -r -p X myBack.CAB]
= loShell.Run(lcBatCmd,1,.t.)
lcBatCmd = lcCmd + [myNextBatchCommand]
= loShell.Run(lcBatCmd,1,.t.)
.. etc..
If you keep the 1 in above statement, the batch command will be visible in a black DOS shell screen.
If you make that to 0 instead of 1, the DOS screen will not be visible.
After the completion of execution only the next lines will be proceeded in loShell.Run() shown above.
____________________________________________
ramani - (Subramanian.G)
http://winnersoft.coolfreepages.com/
RE: How do you WAIT for a program or script to finish
How about a class that's got lost of options to control starting and waiting on both DOS and Windows applications? Go to the UT at http://www.universalthread.com/VisualFoxPro/, click the Downloads picture, then enter "api_apprun" (without the quotes) in the Title box and press enter. You should get back a link to:
"API_APPRUN in .VCX form February 22, 2003
This contains PROCESS.VCX - a visual class library for the API_APPRUN class described in the FAQ. The class gives the ability to run DOS and WinApps from inside VFP using the CreateProcess() API call, and allows you to wait on termination or return immediately, and allows you to examine the execution status and termination code from an executable run by the class.
It takes care of managing the process and thread handles, removing some potential memory bleeds from not properly disposing of proce..."
I've used this in a number of different ways.
Rick