Results 1 to 5 of 5

Thread: Help with batch files

  1. #1

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    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




  2. #2
    Member
    Join Date
    Jun 2000
    Location
    Gainesville, Ga
    Posts
    50

    Question Just a guess

    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]
    Scott Cato
    VB6s

  3. #3
    Junior Member
    Join Date
    May 2000
    Location
    China
    Posts
    25

    Wink Key if useing Win9x

    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!



  4. #4
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    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;

    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
    Then just call..

    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

    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  5. #5

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Thanks To All Of You...


    Best Regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width