Wait until Shell command is finished (ftp example)

  • Thread starter Thread starter George A
  • Start date Start date
G

George A

I'm trying to send a file via ftp.exe, and then read the
log file generated by that command. The problem is that
my program continues after I've shell to ftp, and does not
wait until ftp is finished; my log file is incomplete.
I tried a loop (shown below) to wait until the log file is
present, but the file is apparently cataloged before it is
complete.

Any help you can offer is greatly appreciated.
Thanks
George

PS: I am open to any solution. (I'm not tied to this
direction).

Function ftp_Shell()
strKeyFile = "C:\MyKeys.txt"
strLogFile = "C:\MyLog.prn"
strShellCommand = Replace("%comspec% /c ftp.exe -s:|" &
strKeyFile & "| >|" & strLogFile & "|", "|", Chr(34))
objShell.Run strShellCommand, 0, True


'_________________________________
'Return when log is complete
Dim intFileNumber As Variant
Do While Dir(strLogFile, vbNormal) = ""
DoEvents
Loop
Debug.Print strLogFile

End Function
 
Thank you for your suggestion.
The mvps.org/access page is one of my favorites; I've
learned a lot there.

The code you indicated may have been confused by the
"%comspect% / c"
part of the command. It took me a long time to discover
that that was the key to capturing the log file using >.
In any case, Terry Kreft's code (that you directed me to)
apparently did not execute when I used
ShellWait strShellCommand

Are there any other ways of checking that a file is
created and complete?
Maybe we could try to set an archive bit or something that
would fail if the file is still being written to.

Thank you again for your help.
George
 
Well, dont know really how to workaround this %comspec%, but maybe you can
just replace it with command.com?
or just replace it with Environ("comspec"), which do the same, so your line
will be:
Environ("comspec") & " /c ftp.exe"
 
Back
Top