|
-
Apr 2nd, 2003, 05:01 AM
#1
Thread Starter
Lively Member
-
Apr 2nd, 2003, 05:23 AM
#2
Hyperactive Member
Hello Singapore,
Bet its warmer there.
Anyway to the point.
I presume that your perl program opens the text file for write thus locking it.
what you could do is a loop with a sleep in it (trapping the error) and keep retrying until you can open the textfile exclusively for reading!!
On Error Resume Next
Dim finished As Boolean
finished = False
Do While finished = False
Open "c:\john.txt" For Binary Access Read Lock Read As #1
finished = True
Loop
Close #1
-
Apr 2nd, 2003, 07:06 AM
#3
Here is a function that starts a process, and wits until it has finished, or the timeout is passed.
VB Code:
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessId As Long
dwThreadID As Long
End Type
Const NORMAL_PRIORITY_CLASS = &H20
Const IDLE_PRIORITY_CLASS = &H40
Const HIGH_PRIORITY_CLASS = &H80
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
As Long) As Long
Private Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As _
String, ByVal lpProcessAttributes As Long, ByVal _
lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, lpStartupInfo As _
STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) _
As Long
Public Sub ShellNWait(CommandLine As String, Optional WaitForMilliseconds As Long = -1&, Optional Priority As Long = NORMAL_PRIORITY_CLASS)
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim lRet As Long
On Error Resume Next
'Initialize the STARTUPINFO structure:
Start.cb = Len(Start)
'Start the shelled application:
lRet = CreateProcessA(0&, CommandLine, 0&, 0&, 1&, _
Priority, 0&, 0&, Start, proc)
'Wait for the shelled application to finish:
'use -1 to specify no "timeout" length.
lRet = WaitForSingleObject(proc.hProcess, WaitForMilliseconds)
lRet = CloseHandle(proc.hProcess)
lRet = CloseHandle(proc.hThread)
End Sub
P.S. I copied the code from a post brenaaro posted, and modified it a little to fix a little bug.
Here is the original thread:
http://www.vbforums.com/showthread.p...hreadid=221401
-
Apr 2nd, 2003, 10:24 AM
#4
Thread Starter
Lively Member
Frans C...Did u look into my attached file.I've got a "similar" code there but I dont c any condition there to check my files ....?! Is there?? And for u , John, where should I place the code..according to tat shell functionwhich is attached?? Thanks for both ur replies..Hope to hear from u.
-
Apr 2nd, 2003, 11:07 AM
#5
You could check the files last modified date, using VB's FileDateTime function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|