The goal is to monitor downloads done with aria2c - - The ultra fast download utility
Code: Select all
D:\Download\aria2c.exe --log-level=notice --log="D:\Download\Aria2c.log" -x16 -s16 --allow-overwrite=true --auto-file-renaming=false -d"D:\Download\Mozilla Firefox Quantum ESR_x64" -o"FirefoxSetup_en_win64.exe" "https://download.mozilla.org/?product=firefox-esr-next-latest-ssl&os=win64&lang=en"
Code: Select all
Dir /C /O:GS %SystemRoot%
For /L %i IN (1,1,5) Do @(Ping -n 2 127.0.0.1 -w 250 > Nul & Echo | Set /p Dummy=■)
How could it be done if I have both lines and a progress bar?
Code: Select all
EnableExplicit
Procedure.s Oem2Unicode(OEM_in_unicode.s)
Protected Oem_in_Ascii.s, ByteLength, Unicode.s
ByteLength = Len(OEM_in_unicode) + 2
Oem_in_Ascii = Space(ByteLength)
PokeS(@Oem_in_Ascii, OEM_in_unicode, -1, #PB_Ascii)
Unicode = Space(ByteLength)
OemToChar_(@Oem_in_Ascii, @Unicode)
ProcedureReturn Unicode
EndProcedure
Define Size, String.s, Output.s, Error.s
Define CmdParm.s = "/C For /L %i IN (1,1,5) Do @(Ping -n 2 127.0.0.1 -w 250 > Nul & Echo | Set /p Dummy=■)"
;Define CmdParm.s = "/C Dir /C /O:GS %SystemRoot%"
Define hCmd = RunProgram("cmd.exe", CmdParm, "", #PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide)
If hCmd
While ProgramRunning(hCmd)
Size = AvailableProgramOutput(hCmd)
If Size
; Looks good with For /L but not with Dir /C, with at the end, if you close the console: The debugged executable quit unexpectedly
Define *Buffer = AllocateMemory(1024)
Size = ReadProgramData(hCmd, *Buffer, Size)
If Size
String = Oem2Unicode(PeekS(*Buffer, Size, #PB_Ascii))
Output + String
ClearDebugOutput()
Debug Output
EndIf
; Looks good for Dir /C. With For /L the progress bar is only displayed at the end
;String = Oem2Unicode(ReadProgramString(hCmd, #PB_Ascii))
;Debug String
;Output + String + #CRLF$
Error + Oem2Unicode(ReadProgramError(hCmd, #PB_Ascii)) + #CRLF$
EndIf
Wend
If ProgramExitCode(hCmd) <> 0
Error + Oem2Unicode(ReadProgramError(hCmd, #PB_Ascii)) + #CRLF$
MessageRequester("Error " + GetCurrentDirectory(), "Error Cmd:" + Error, #PB_MessageRequester_Ok | #PB_MessageRequester_Error)
EndIf
;Debug Output
CloseProgram(hCmd)
EndIf
; IDE Options = PureBasic 6.03 LTS (Windows - x64)
; ExecutableFormat = Console
; EnableXP
; CompileSourceDirectory