ejecutar programa con parámetros

Iniciado por Hans el Topo, 18 Septiembre 2008, 19:18 PM

0 Miembros y 1 Visitante están viendo este tema.

Hans el Topo

saludos, 

estoy ejecutando un programa desde vb6, más concretamente mysqldump para realizar backups,  de la siguiente manera :

CitarShell ruta & "mysqldump.exe blablablbal  -r ""c:\backup_prueba.sql"" 2>&1", vbNormalFocus

el ejecutable lo lanza bien pero parece ser que detiene el proceso antes de que termine,
alguien conoce alguna manera de que siga ejecutándolo hasta que termine y luego prosiga con el código vb6? se puede hacer?






 

aaronduran2

#1
Código (vb) [Seleccionar]
Option Explicit

Private Declare Function CreateProcess Lib "Kernel32" Alias _
                                            "CreateProcessA" ( _
    ByVal lpAppName As Long, _
    ByVal lpCmdLine As String, _
    ByVal lpProcAttr As Long, _
    ByVal lpThreadAttr As Long, _
    ByVal lpInheritedHandle As Long, _
    ByVal lpCreationFlags As Long, _
    ByVal lpEnv As Long, _
    ByVal lpCurDir As Long, _
    lpStartupInfo As STARTUPINFO, _
    lpProcessInfo As PROCESS_INFORMATION _
) As Long
     
Private Declare Function WaitForSingleObject Lib "Kernel32" ( _
    ByVal hHandle As Long, _
    ByVal dwMilliseconds As Long _
) As Long
   
Private Declare Function CloseHandle Lib "Kernel32" ( _
    ByVal hObject As Long _
) As Long
   
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&

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 Integer
    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
 
Public Function ShellWait(CmdLine As String, Optional ByVal _
                        bShowApp As Boolean = False) As Boolean
       
    Dim uProc As PROCESS_INFORMATION
    Dim uStart As STARTUPINFO
    Dim lRetVal As Long
   
    uStart.cb = Len(uStart)
    uStart.wShowWindow = Abs(bShowApp)
    uStart.dwFlags = 1
   
    lRetVal = CreateProcess(0&, CmdLine, 0&, 0&, 1&, _
                            NORMAL_PRIORITY_CLASS, 0&, 0&, _
                            uStart, uProc)
   
    lRetVal = WaitForSingleObject(uProc.hProcess, INFINITE)
   
    lRetVal = CloseHandle(uProc.hProcess)
    lRetVal = CloseHandle(uProc.hThread)
   
    ShellWait = (lRetVal <> 0)
End Function


Saludos.

Hans el Topo

muchas gracias

últimamente estoy muy torpe

para que funcione correctamente hay que agregar "cmd.exe /c " y luego el comando que se desee ejecutar sino pasa olímpicamente de esperar