Laisse tomber la console PureBasic, car elle n'intègre pas de barre de défilement, ce qui est peu pratique si tu veux voir ce qui s'est passé avant / si une commande renvoie plus d'infos que l'écran !
Test ce code :
Code : Tout sélectionner
; Redirect Outputs into Memory (redirected the pipes)
; coded by Siegfried Rings march 2002
; Tweaked by Droopy ( 03/05/05 )
;see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q173085
;Structure used by the CreateProcessA function
;another then that Fred implemented !
Structure MySTARTUPINFO
cb.l
lpReserved.l
lpDesktop.l
lpTitle.l
dwX.l
dwY.l
dwXSize.l
dwYSize.l
dwXCountChars.l
dwYCountChars.l
dwFillAttribute.l
dwFlags.l
wShowWindow.w
cbReserved2.w
lpReserved2.l
hStdInput.l
hStdOutput.l
hStdError.l
EndStructure
Procedure.s ConformationAsciiEtenduVersAscii(Text.s)
ReplaceString(Text,Chr(130),"é",2)
ReplaceString(Text,Chr(135),"ç",2)
ReplaceString(Text,Chr(131),"â",2)
ReplaceString(Text,Chr(133),"à",2)
ReplaceString(Text,Chr(136),"ê",2)
ReplaceString(Text,Chr(137),"ë",2)
ReplaceString(Text,Chr(138),"è",2)
ReplaceString(Text,Chr(140),"î",2)
ReplaceString(Text,Chr(150),"û",2)
ReplaceString(Text,Chr(151),"ù",2)
ReplaceString(Text,Chr(240),"-",2)
ReplaceString(Text,Chr(242),"=",2)
ReplaceString(Text,Chr(255)," ",2)
; Nettoie des caractères < 31
For n=1 To 31
If n=9 : Continue : EndIf
If n=10 : Continue : EndIf ; LF fout la zone je le supprime
; If n=13 : Continue : EndIf
ReplaceString(Text,Chr(n),"",2)
Next
ProcedureReturn Text
EndProcedure
Procedure.s GetProgramResult(Command.s)
proc.PROCESS_INFORMATION ;Process info filled by CreateProcessA
ret.l ;long variable For get the Return value of the
start.MySTARTUPINFO ;StartUp Info passed To the CreateProceeeA
sa.SECURITY_ATTRIBUTES ;Security Attributes passeed To the
hReadPipe.l ;Read Pipe handle created by CreatePipe
hWritePipe.l ;Write Pite handle created by CreatePipe
lngBytesread.l ;Amount of byte Read from the Read Pipe handle
strBuff.s=Space(256) ;String buffer reading the Pipe
;Consts For functions
#NORMAL_PRIORITY_CLASS = $20
#STARTF_USESTDHANDLES = $100
#STARTF_USESHOWWINDOW = $1
;Create the Pipe
sa\nLength =SizeOf(SECURITY_ATTRIBUTES) ;Len(sa)
sa\bInheritHandle = 1
sa\lpSecurityDescriptor = 0
ret = CreatePipe_(@hReadPipe, @hWritePipe, @sa, 0)
If ret = 0
;If an error occur during the Pipe creation exit
MessageRequester("info", "CreatePipe failed. Error: ",0)
End
EndIf
start\cb = SizeOf(MySTARTUPINFO)
start\dwFlags = #STARTF_USESHOWWINDOW | #STARTF_USESTDHANDLES
;set the StdOutput And the StdError output To the same Write Pipe handle
start\hStdOutput = hWritePipe
start\hStdError = hWritePipe
;Execute the command
ret = CreateProcess_(0, Command, sa, sa, 1, #NORMAL_PRIORITY_CLASS, 0, 0, @start, @proc)
If ret <> 1
retour.s=""
Else
;Now We can ... must close the hWritePipe
ret = CloseHandle_(hWritePipe)
mOutputs.s = ""
;Read the ReadPipe handle
While ret<>0
ret = ReadFile_(hReadPipe, strBuff, 255, @lngBytesread, 0)
If lngBytesread>0
mOutputs = mOutputs + Left(strBuff, lngBytesread)
EndIf
Wend
;Close the opened handles
ret = CloseHandle_(proc\hProcess)
ret = CloseHandle_(proc\hThread)
ret = CloseHandle_(hReadPipe)
;ret=CloseHandle_(hWritePipe)
retour.s=mOutputs
EndIf
ProcedureReturn ConformationAsciiEtenduVersAscii(mOutputs)
EndProcedure
Commande.s="Cmd /c dir c:\"
MessageRequester(Commande,GetProgramResult(Commande))
Commande.s="net start"
MessageRequester(Commande,GetProgramResult(Commande))
Commande.s="ping localhost"
MessageRequester(Commande,GetProgramResult(Commande))
Le code est de Siegfried, je l'ai modifié quelque peu, je pense intégrer cette fonction dans la prochaine version de ma lib.