Executing 16Bit Command Line App with VB6 
Author Message
 Executing 16Bit Command Line App with VB6

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.



Mon, 23 Jun 2003 03:45:54 GMT  
 Executing 16Bit Command Line App with VB6
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.



Mon, 23 Jun 2003 21:32:41 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Executing command to command line from VB App

2. How do you execute a Command line App inside a VB program

3. Executing command line apps

4. How to execute a command line command from a *.HTA

5. Use Shell to execute a 16bit app in separate memory

6. Migrating VB4 Btrieve app to VB6 (16bit to 32bbit)

7. Executing a command line using code

8. Executing command line function from VBA (Excel)

9. VBA script - execute from command line

10. AutoNew fails to execute from command line

11. Executing command-line EXE and retrieving output

12. executing vb programs using command line parameters

 

 
Powered by phpBB® Forum Software