I would guess that what is really happening is that the Windows
programming kicks off the DOS App and then starts reading the output
files before the DOS program has closed.
One easy method is for the DOS App to create a 'signal' file when it
has finished
Another is this - there is enough in here to wait until it is done :-
Option Explicit
'To Kill a DOS app: Jason Bouzane
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 Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" _
(ByVal hProcess As Long, _
ByVal uExitCode As Long) As Long
Private Const SYNCHRONIZE = &H100000
Private Const WAIT_TIMEOUT = &H102
Private Const PROCESS_TERMINATE = &H1
Sub CallDos(Cmd$)
Dim hProcess As Long
Dim pID As Long
Dim lRet As Long
Dim Style As Integer
Dim TimeOutSecs As Long
TimeOutSecs = 6
' Style = vbHide
Style = vbNormalFocus
pID = Shell(Environ("Comspec") + " /C " + Cmd, Style)
hProcess = OpenProcess(SYNCHRONIZE, False, pID)
lRet = WaitForSingleObject(hProcess, TimeOutSecs * 1000)
If lRet = WAIT_TIMEOUT Then
CloseHandle hProcess
hProcess = OpenProcess(PROCESS_TERMINATE, False, pID)
If hProcess = 0 Then Exit Sub
TerminateProcess hProcess, 0
CloseHandle hProcess
End If
End Sub
Private Sub Command1_Click()
CallDos "DIR C:\ /P"
MsgBox "I GOT BACK"
End Sub
On Wed, 3 Jan 2001 19:45:54 -0000, "Tim Rhodes"
Quote:
>Happy New Year everyone!
>I have a situation at the moment and could really do with some help ;-)
>I am writing a VB GUI-wrapper for a 16bit DOS executable. The idea is to
>give it a much more user friendly frontend. The dos app uses comma-separated
>data files for input, control and output. My VB app generates the input and
>control text files shells the dos app and picks up the results from another
>pair of csv text files. Sounds simple so far doesn't it?
>Well I have a problem! My code correctly generates all the necessary files
>and does not keep them open during the execution of the dos app (so no
>sharing violations are generated). However, the dos app doesn't generate the
>results file correctly when I use 'SHELL' in VB to execute it. However, when
>I run it manually (from dos box) it does!!
>I have tried using OpenProcess and Shell, as well as CreateProcess and
>WindExec. I'm running out of ideas. It all works properly when run by hand
>but when it is shelled the results are not generated. Could it be a problem
>with the exit routine of the dos app? Can you you use the FileSystemObject
>to execute applications?
>If anybody can help I would be very grateful.
>All the very best for 2001.
>Tim
>PS. I'm using Win98SE and VB6SP4.