I'm Running a DOS Appl and i am redirecting the output to a file.
RetVal= Shell(BatFile, vbHide) ' run the bat
1) How do i close Dos appl??
2) How colud i know if my bat file is finished executing ?? (i want to read the output).
Regards
Printable View
I'm Running a DOS Appl and i am redirecting the output to a file.
RetVal= Shell(BatFile, vbHide) ' run the bat
1) How do i close Dos appl??
2) How colud i know if my bat file is finished executing ?? (i want to read the output).
Regards
I'm not any of those guys you mentioned in the title,
And nowhere near the programmer, But i thought I'd
mention:
You might try setting the PIF for the DOS file to
"Close On Exit".
[Edited by catocom on 07-11-2000 at 12:29 AM]
You can runing your BAT File in this way
Dim ProcessID As Long
Dim ProcessHandle As Long
ProcessID = Shell(BATFile, vbHide)
ProcessHandle = OpenProcess(SYNCHRONIZE, True, ProcessID)
'and you can stop it in this way
TerminateProcess ProcessHandle, 0&
CloseHandle ProcessHandle
'OpenProcess and TerminateProcess and CloseHandle are API function
If you wanna read the output,you can use the "MSDOS WAY" like that: "DIR C:\ >>a.txt".So ,use "DO..LOOP" to exam if the "a.txt" exist(dir(a.txt)<>"") and "a.txt" is what you want!
I'm not one of the people mentioned in the subject and frankly it gets a bit annoying when people think that there are only a handful of people on this bb that can answer questions!!
Try this;
Then just call..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
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
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Sub ExecCmd(cmdline$)
Dim proc As Process_Information
Dim start As StartupInfo
Dim ret As Long
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ret = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
ret = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, ret&)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
End Sub
ExecCmd("MYDOSPROGRAM.EXE")
and VB will not continue executing until the program has finished - in order to make a DOS program close when it has finished (without using the properties);
ExecCmd("COMMAND.COM /C MYEXE.EXE") for Windows '95/'98
ExecCmd("CMD.EXE /C MYEXE.EXE") for Windows NT
Thanks To All Of You...
Best Regards