Newsgroup: it.comp.lang.visual-basic
Titolo: output di dos

Salve a tutti!
Sapete come si fa a catturare l'output di nerocmd.exe lanciato con
shellexecute? Mi servirebbe per mostrare le varie operazione compiute
dal nerocmd.exe in una textbox o qlc del genere in modo  da non far
apparire una shell di dos all'utente, mantenendolo però aggiornato
delle varie operazioni di masterizzazione... qualcosa del genere è
stato fatto con 'xduplicator', una GUI per cdrdao.exe, però non so con
quale linguaggio è stato creato.
Grazie mille

delle varie operazioni di masterizzazione... 
Con ShellExecute non saprei, io preferirei seguire questa strada:
1. creo una pipe (vedi CreatePipe dell' api);
2. avvio il processo con CreateProcess, passandogli l'handle della
pipe per l'output;
3. leggo il contenuto della pipe con ReadFile e lo copio a video in
una textbox multiline, ad esempio.
Esempio:
<codice>
Private Const STARTF_USESTDHANDLES = &H100
Private Const STARTF_USESHOWWINDOW = &H1
Private Const SW_HIDE = 0
Private Const NORMAL_PRIORITY_CLASS = &H20
Private Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessId As Long
    dwThreadId As Long
End Type
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 SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
End Type
Private Declare Function CreatePipe Lib "kernel32" ( _
                            phReadPipe As Long, phWritePipe As Long, _
                            lpPipeAttributes As SECURITY_ATTRIBUTES, _
                            ByVal nSize As Long _
                            ) As Long
Private Declare Function CreateProcess Lib "kernel32" Alias
"CreateProcessA" ( _
                            ByVal lpApplicationName As String, _
                            ByVal lpCommandLine As String, _
                            ByRef lpProcessAttributes As
SECURITY_ATTRIBUTES, _
                            ByRef lpThreadAttributes As
SECURITY_ATTRIBUTES, _
                            ByVal bInheritHandles As Long, ByVal
dwCreationFlags As Long, _
                            ByRef lpEnvironment As Any, ByVal
lpCurrentDriectory As String, _
                            ByRef lpStartupInfo As STARTUPINFO, _
                            ByRef lpProcessInformation As
PROCESS_INFORMATION _
                            ) As Long
Private Declare Function CloseHandle Lib "kernel32" ( _
		ByVal hObject As Long) As Long
Private Declare Function ReadFile Lib "kernel32" ( _
                     ByVal hFile As Long, ByRef lpBuffer As Any, _
                     ByVal nNumberOfBytesToRead As Long, _
                     ByRef lpNumberOfBytesRead As Long, _
                     ByRef lpOverlapped As Any _
                     ) As Long       
Public Function ExecApp(ByVal cmdLine As String) As String
    Dim proc As PROCESS_INFORMATION
    Dim si As STARTUPINFO
    Dim sa As SECURITY_ATTRIBUTES
    Dim hPipeR As Long ' pipe in lettura
    Dim hPipeW As Long ' pipe in scrittura
    Dim sOut As String
    Dim nBytes As Long
    Dim sBuffer As String * 256
    Dim retVal As Long
    sa.nLength = Len(sa)
    sa.bInheritHandle = True
 
    If (0 = CreatePipe(hPipeR, hPipeW, sa, 0)) Then
        MsgBox "CreatePipe failed. Error #" & Err.LastDllError
        Exit Function
    End If
    si.cb = Len(si)
    si.dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW
    si.hStdOutput = hPipeW
    si.hStdError = hPipeW
    si.wShowWindow = SW_HIDE
 
    If (0 = CreateProcess(vbNullString, sCmdline, sa, sa, _
			True, NORMAL_PRIORITY_CLASS, _
                        ByVal vbNullString, _
			ByVal vbNullString, si, proc) Then
        MsgBox "CreateProcess failed. Error #" & Err.LastDllError
        Exit Function
    End If
 
    CloseHandle (hPipeW)
    Do
        retVal = ReadFile(hPipeR, _
			ByVal sBuffer, 256, _
			nBytes, ByVal 0&)
        sOut = sOut & Left$(sBuffer, nBytes)
	' oppure se siamo in un modulo di classe 
	' qui si puo' generare un evento
	' RaiseEvent NomeEvento(Left$(sBuffer, nBytes))
    Loop While (retVal <> 0)
    CloseHandle (proc.hProcess)
    CloseHandle (proc.hThread)
    CloseHandle (hPipeR)
    ' restituiamo tutto l'output
    ExecApp = sOutput
    ' oppure non restituiamo nulla perche' abbiamo
    ' gia' sollevato eventi in precedenza
End Function
</codice>
-- 
hth, hal

>apparire una shell di dos all'utente, mantenendolo perň aggiornato
