Click to See Complete Forum and Search --> : How can I see that the program (executed by SHELL Func') completed?
elik
June 20th, 2001, 02:36 AM
Hi,
I use Shell function to run a batch file that get some arguments, Then the Batch file write a log file, which I read and analyze. The problem is that i need to automatically analyze it as soon as the batch file completed it task.But, I dont now how to know whether the batch file has completed to run. do you know how?
Shell path_lcl_drive.Text & Scc_Batch_File & " " & _
sccipadrs.Text & " " & win_ver.Text & " " & setup_ver.Text & _
" " & scc_dir_updt_virtex.Text & " " & src_sub_dir_virtex.Text & " " & path_cptn.Text & " " & path_lcl_drive.Text, vbMaximizedFocus
Eli
cksiow
June 20th, 2001, 02:46 AM
check http://vblib.virtualave.net, there is a function called RunAppWait in vbSystem of the activeX DLL which will run a program and wait until it finish.
HTH
cksiow
http://vblib.virtualave.net - share our codes
Cimperiali
June 20th, 2001, 03:11 AM
'one form (name = Fwait)
'one commandButton (=Command1)
option Explicit
Const INFINITE = -1&
private Declare Function WaitForSingleObject Lib "kernel32" (byval hHandle as Long, byval dwMilliseconds as Long) as Long
private Declare Function OpenProcess Lib "kernel32" (byval dwDesiredAccess as Long, byval bInheritHandle as Long, byval dwProcessId as Long) as Long
private Function Chiama_E_Attendi(sFile as string) as Long
Dim lngExecOK as Long
Dim lProcessHandle as Long
Dim lReturnValue as Long
on error GoTo errHandler
If Dir(sFile) <> "" then
me.Hide 'hide this form, to see it come back when process ends
lngExecOK = Shell(sFile, vbNormalFocus)
'handle to process
lProcessHandle = OpenProcess(&H100000, true, lngExecOK)
'Wait
lReturnValue = WaitForSingleObject(lProcessHandle, INFINITE)
me.Show 'showme again
'MsgBox "Ended execution " & Now
Chiama_E_Attendi = lReturnValue
else
MsgBox "file not found"
End If
Exit Function
errHandler:
MsgBox Err & Space(2) & error$
Err.Clear
Unload me
set FWait = nothing
End Function
private Sub Command1_Click()
Dim ret
ret = Chiama_E_Attendi("c:\windows\notepad.exe")
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
Cimperiali
June 20th, 2001, 03:19 AM
A batch file? you mean it has no window? Well, I am afraid my code will not work...
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
cksiow
June 20th, 2001, 03:31 AM
it will if he run some dos program, as it will bring up a dos prompt window, just remember to check on the close on exit for the property page.
HTH
cksiow
http://vblib.virtualave.net - share our codes
praveen b p
June 20th, 2001, 04:35 AM
Check the return value of the Shell()if it returns 0 then Shell() has not executed correctly otherwise Shell() has executed correctly. I think this code snippet may help you..
Dim RetVal
RetVal = Shell("C:\Test.bat", 1)
if RetVal=0 then
msgbox "Failure"
else
msgbox "Success"
end if
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.