×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

Monitor Size of text file as created

Monitor Size of text file as created

Monitor Size of text file as created

(OP)
I am using shellexecute to run a command and using '>' to output the displayed text to a text file.
The problem I have is that the file is missing text as my program continues on to open the file and parse the text.
How can I get my program to pause until shellexecute is finished?
I can declare a sleep which does work after a fashion but I have to estimate the longest time it will take.
It would be better if I could monitor the file size with a Do While function until the file size has stopped increasing.

Any suggestions?

Alastair

RE: Monitor Size of text file as created

I suggest the following sequence:
1. Create a file to indicate that the process is not finished, for instance NotFinished.txt. Strtofile() is fine for this
2. Run your ShellExecute routine
3. Delete the file mentioned in 1
3. Let the VFP program you refer to run in a loop until the file mentioned in 1 is not found anymore.

RE: Monitor Size of text file as created

Quote:

How can I get my program to pause until shellexecute is finished?

You can't. Once you have launched a program with ShellExecute(), that program exists independently of VFP. You can't control it in any way from your VFP application. The best you can do is to use API calls to look through all the open windows on the desktop, checking for one whose title matches that of the launched program. But it's not a very reliable method.

As an alternative, consider using this code in place of ShellExecute()

CODE -->

oWSH = CREATEOBJECT("wscript.shell")
oWSH.Run("MyProg", 3, .T.) 

where "MyProg" is the program you want to execute, including the full path and EXE name. The second parameter says how you want the program window to appear (3 = maximised). Importantly, by passing .T. as the third parameter, you tell your calling program to pause until the called program has finished executing.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Monitor Size of text file as created

(OP)

I came up with this:
Tested and seems to work.
I will look at your suggestion as well Mike.

Alastair

CODE

lnSize = -1
nSize =0

lcFileIsComplete=.f.
DO WHILE lcFileIsComplete=.f.
	DECLARE Sleep IN Win32API INTEGER nMilliseconds
	Sleep(10)
	lnFile=ADIR(arr,lcFile,"D",1)
	IF lnFile = 0 
		LOOP 
	ENDIF 	
	nSize =arr(1,2)
	IF nSize=0
		LOOP
	ENDIF 	
	IF nSize = lnSize 
		lcFileIsComplete=.t.
		EXIT 
	ENDIF 
	lnSize 	= nSize 
ENDDO 

RE: Monitor Size of text file as created

(OP)
Mike, I tried your suggestion, but I had an ole error that it could not wait for process when I had the last parameter set to .t.

Anyway, that aside, does this wscript return a window handle so I can close the open window I just opened with the command?
FYI I am trying to activate a remote share on a server that once connected needs a kick start by typing in the ip address in an explorer bar.

RE: Monitor Size of text file as created

Scott,

No, the script doesn't return a handle. As far as I can see, it always returns zero.

I suspect that your OLE error occurs because it does not recognise - or cannot find - the file or command that you passed to it. Although if ShellExecute() worked, then this should as well. Sorry I can't suggest anything else.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Monitor Size of text file as created

By the way, Alastair, there is a small problem with the code that you posted. You really need to take the DECLARE Sleep outside the DO WHILE loop. You only need to do it once. Doing inside the loop will still work, but will lead to a (probably negligible) drop in performance.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Monitor Size of text file as created

(OP)
Hi Mike,
Oh great, thanks for that.
Its short on a bit of validation too and could get stuck in a loop if the file is empty. I will run a counter and exit after a number of loops.

Alastair

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close