Jump to content

Real-Time CMD Output


Recommended Posts

Hi guys, for educational purpose i want to make a script for read a CMD output and make a progress bar for it

P.S I know the InetGet command, but i have other command-line software based on the same principle

The script:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
 
$GUI = GUICreate("Test", 270, 329, 248, 123)
$List = GUICtrlCreateList("", 8, 8, 249, 227)
GUICtrlSetData(-1, "")
$ProgressBar = GUICtrlCreateProgress(8, 248, 249, 25)
$ButtonStart = GUICtrlCreateButton("Start!", 8, 288, 250, 25)
GUISetState(@SW_SHOW)
 
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $ButtonStart
   Example()
EndSwitch
WEnd

Func Example()
GUICtrlSetData($List, _ReadDos('C:\wget.exe [url="http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe"]http://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe'[/url]) & @CRLF)
EndFunc
 
Func _ReadDOS($command)
    Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2+4)
    While 1
        $text &= StdoutRead($Pid, False, False)
        If @error Then ExitLoop
        Sleep(10)
    WEnd
    Return $text
EndFunc

The wget link for test:

http://users.ugent.be/~bpuype/cgi-bin/fetch.pl?dl=wget/wget.exe

For me not work, i don't have the list updated. But i see the progress on Console:

Resolving www.autoitscript.com... 87.106.181.57
Connecting to www.autoitscript.com|87.106.181.57|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://www.autoitscript.com/files/autoit3/autoit-v3-setup.exe [following]
--2012-02-12 09:47:08--  http://www.autoitscript.com/files/autoit3/autoit-v3-setup.exe
Reusing existing connection to www.autoitscript.com:80.
HTTP request sent, awaiting response... 200 OK
Length: 7377952 (7.0M) [application/octet-stream]
Saving to: `autoit-v3-setup.exe.2'
     0K .......... .......... .......... .......... ..........  0% 82.7K 87s
    50K .......... .......... .......... .......... ..........  1%  219K 59s
   100K .......... .......... .......... .......... ..........  2%  280K 48s
   150K .......... .......... .......... .......... ..........  2%  512K 39s
   200K .......... .......... .......... .......... ..........  3%  614K 33s
   250K .......... .......... .......... .......... ..........  4%  513K 30s
   300K .......... .......... .......... .......... ..........  4%  568K 27s
   350K .......... .......... .......... .......... ..........  5%  602K 25s
   400K .......... .......... .......... .......... ..........  6%  615K 23s
   450K .......... .......... .......... .......... ..........  6%  613K 22s
   500K .......... .......... .......... .......... ..........  7%  596K 21s
   550K .......... .......... .......... .......... ..........  8%  612K 20s
   600K .......... .......... .......... .......... ..........  9%  614K 19s
   650K .......... .......... .......... .......... ..........  9%  614K 18s
   700K .......... .......... .......... .......... .......... 10%  597K 18s
   750K .......... .......... .......... .......... .......... 11%  612K 17s
   800K .......... .......... .......... .......... .......... 11%  618K 16s
   850K .......... .......... .......... .......... .......... 12%  612K 16s
   900K .......... .......... .......... .......... .......... 13%  595K 16s
   950K .......... .......... .......... .......... .......... 13%  612K 15s
  1000K .......... .......... .......... .......... .......... 14%  614K 15s
  1050K .......... .......... .......... .......... .......... 15%  611K 14s
  1100K .......... .......... .......... .......... .......... 15%  595K 14s
  1150K .......... .......... .......... .......... .......... 16%  614K 14s
  1200K .......... .......... .......... .......... .......... 17%  617K 14s
  1250K .......... .......... .......... .......... .......... 18%  592K 13s
  1300K .......... .......... .......... .......... .......... 18%  619K 13s
  1350K .......... .......... .......... .......... .......... 19%  611K 13s
  1400K .......... .......... .......... .......... .......... 20%  592K 13s
  1450K .......... .......... .......... .......... .......... 20%  615K 12s
  1500K .......... .......... .......... .......... .......... 21%  613K 12s
  1550K .......... .......... .......... .......... .......... 22%  615K 12s
  1600K .......... .......... .......... .......... .......... 22%  616K 12s
  1650K .......... .......... .......... .......... .......... 23%  595K 12s
  1700K .......... .......... .......... .......... .......... 24%  610K 11s
  1750K .......... .......... .......... .......... .......... 24%  614K 11s
  1800K .......... .......... .......... .......... .......... 25%  615K 11s
  1850K .......... .......... .......... .......... .......... 26%  596K 11s
  1900K .......... .......... .......... .......... .......... 27%  604K 11s
  1950K .......... .......... .......... .......... .......... 27%  624K 11s
  2000K .......... .......... .......... .......... .......... 28%  612K 10s
  2050K .......... .......... .......... .......... .......... 29%  596K 10s
  2100K .......... .......... .......... .......... .......... 29%  610K 10s
  2150K .......... .......... .......... .......... .......... 30%  616K 10s
  2200K .......... .......... .......... .......... .......... 31%  600K 10s
  2250K .......... .......... .......... .......... .......... 31%  614K 10s
  2300K .......... .......... .......... .......... .......... 32%  608K 10s
  2350K .......... .......... .......... .......... .......... 33%  613K 9s
  2400K .......... .......... .......... .......... .......... 34%  598K 9s
  2450K .......... .......... .......... .......... .......... 34%  613K 9s
  2500K .......... .......... .......... .......... .......... 35%  610K 9s
  2550K .......... .......... .......... .......... .......... 36%  615K 9s
  2600K .......... .......... .......... .......... .......... 36%  602K 9s
  2650K .......... .......... .......... .......... .......... 37%  608K 9s
  2700K .......... .......... .......... .......... .......... 38%  616K 9s
  2750K .......... .......... .......... .......... .......... 38%  612K 8s
  2800K .......... .......... .......... .......... .......... 39%  558K 8s
  2850K .......... .......... .......... .......... .......... 40%  659K 8s
  2900K .......... .......... .......... .......... .......... 40%  612K 8s
  2950K .......... .......... .......... .......... .......... 41%  613K 8s
  3000K .......... .......... .......... .......... .......... 42%  599K 8s
  3050K .......... .......... .......... .......... .......... 43%  612K 8s
  3100K .......... .......... .......... .......... .......... 43%  616K 8s
  3150K .......... .......... .......... .......... .......... 44%  615K 8s
  3200K .......... .......... .......... .......... .......... 45%  592K 7s
  3250K .......... .......... .......... .......... .......... 45%  612K 7s
  3300K .......... .......... .......... .......... .......... 46%  612K 7s
  3350K .......... .......... .......... .......... .......... 47%  594K 7s
  3400K .......... .......... .......... .......... .......... 47%  617K 7s
  3450K .......... .......... .......... .......... .......... 48%  615K 7s
  3500K .......... .......... .......... .......... .......... 49%  612K 7s
  3550K .......... .......... .......... .......... .......... 49%  593K 7s
  3600K .......... .......... .......... .......... .......... 50%  614K 7s
  3650K .......... .......... .......... .......... .......... 51%  614K 7s
  3700K .......... .......... .......... .......... .......... 52%  614K 6s
  3750K .......... .......... .......... .......... .......... 52%  596K 6s
  3800K .......... .......... .......... .......... .......... 53%  615K 6s
  3850K .......... .......... .......... .......... .......... 54%  607K 6s
  3900K .......... .......... .......... .......... .......... 54%  617K 6s
  3950K .......... .......... .......... .......... .......... 55%  593K 6s
  4000K .......... .......... .......... .......... .......... 56%  621K 6s
  4050K .......... .......... .......... .......... .......... 56%  608K 6s
  4100K .......... .......... .......... .......... .......... 57%  614K 6s
  4150K .......... .......... .......... .......... .......... 58%  598K 6s
  4200K .......... .......... .......... .......... .......... 58%  612K 5s
  4250K .......... .......... .......... .......... .......... 59%  618K 5s
  4300K .......... .......... .......... .......... .......... 60%  576K 5s
  4350K .......... .......... .......... .......... .......... 61%  629K 5s
  4400K .......... .......... .......... .......... .......... 61%  613K 5s
  4450K .......... .......... .......... .......... .......... 62%  616K 5s
  4500K .......... .......... .......... .......... .......... 63%  597K 5s
  4550K .......... .......... .......... .......... .......... 63%  611K 5s
  4600K .......... .......... .......... .......... .......... 64%  616K 5s
  4650K .......... .......... .......... .......... .......... 65%  612K 5s
  4700K .......... .......... .......... .......... .......... 65%  592K 4s
  4750K .......... .......... .......... .......... .......... 66%  614K 4s
  4800K .......... .......... .......... .......... .......... 67%  612K 4s
  4850K .......... .......... .......... .......... .......... 68%  617K 4s
  4900K .......... .......... .......... .......... .......... 68%  595K 4s
  4950K .......... .......... .......... .......... .......... 69%  611K 4s
  5000K .......... .......... .......... .......... .......... 70%  618K 4s
  5050K .......... .......... .......... .......... .......... 70%  609K 4s
  5100K .......... .......... .......... .......... .......... 71%  599K 4s
  5150K .......... .......... .......... .......... .......... 72%  613K 4s
  5200K .......... .......... .......... .......... .......... 72%  606K 4s
  5250K .......... .......... .......... .......... .......... 73%  621K 3s
  5300K .......... .......... .......... .......... .......... 74%  595K 3s
  5350K .......... .......... .......... .......... .......... 74%  610K 3s
  5400K .......... .......... .......... .......... .......... 75%  616K 3s
  5450K .......... .......... .......... .......... .......... 76%  597K 3s
  5500K .......... .......... .......... .......... .......... 77%  615K 3s
  5550K .......... .......... .......... .......... .......... 77%  612K 3s
  5600K .......... .......... .......... .......... .......... 78%  611K 3s
  5650K .......... .......... .......... .......... .......... 79%  595K 3s
  5700K .......... .......... .......... .......... .......... 79%  612K 3s
  5750K .......... .......... .......... .......... .......... 80%  618K 3s
  5800K .......... .......... .......... .......... .......... 81%  613K 2s
  5850K .......... .......... .......... .......... .......... 81%  582K 2s
  5900K .......... .......... .......... .......... .......... 82%  630K 2s
  5950K .......... .......... .......... .......... .......... 83%  612K 2s
  6000K .......... .......... .......... .......... .......... 83%  609K 2s
  6050K .......... .......... .......... .......... .......... 84%  596K 2s
  6100K .......... .......... .......... .......... .......... 85%  619K 2s
  6150K .......... .......... .......... .......... .......... 86%  609K 2s
  6200K .......... .......... .......... .......... .......... 86%  613K 2s
  6250K .......... .......... .......... .......... .......... 87%  596K 2s
  6300K .......... .......... .......... .......... .......... 88%  612K 2s
  6350K .......... .......... .......... .......... .......... 88%  615K 1s
  6400K .......... .......... .......... .......... .......... 89%  612K 1s
  6450K .......... .......... .......... .......... .......... 90%  597K 1s
  6500K .......... .......... .......... .......... .......... 90%  613K 1s
  6550K .......... .......... .......... .......... .......... 91%  112K 1s
  6600K .......... .......... .......... .......... .......... 92% 98.7M 1s
  6650K .......... .......... .......... .......... .......... 92% 10.0M 1s
  6700K .......... .......... .......... .......... .......... 93% 17.0M 1s
  6750K .......... .......... .......... .......... .......... 94% 54.8M 1s
  6800K .......... .......... .......... .......... .......... 95% 1.22M 1s
  6850K .......... .......... .......... .......... .......... 95%  467K 1s
  6900K .......... .......... .......... .......... .......... 96%  554K 0s
  6950K .......... .......... .......... .......... .......... 97%  612K 0s
  7000K .......... .......... .......... .......... .......... 97%  599K 0s
  7050K .......... .......... .......... .......... .......... 98%  613K 0s
  7100K .......... .......... .......... .......... .......... 99%  609K 0s
  7150K .......... .......... .......... .......... .......... 99%  617K 0s
  7200K .....                                                100%  658K=13s
2012-02-12 09:47:21 (568 KB/s) - `autoit-v3-setup.exe.2' saved [7377952/7377952]

Thanks for support :)

Link to comment
Share on other sites

I have found a solurion for wget, but why i can't apply to other?

GUICtrlSetData($ProgressBar, 0)
$CMDDir = $soft & ' "' & $URL & '"'
$CMDCommand = Run($CMDDir, @ScriptDir, @SW_HIDE, $STDERR_CHILD)
ProcessSetPriority($CMDCommand, 0)
$streamcounter = 0
While ProcessExists($CMDCommand)
  If 1 <= $streamcounter Then
   $readstream = StderrRead($CMDCommand)
   $tmp = _StringBetween($readstream, ".....", '%')
   If @error <> 1 Then
    $percent = StringReplace($tmp[0], ".", "");
    $percent = StringStripWS($percent, "7");
    GUICtrlSetData($ProgressBar, $percent)
    GUICtrlSetData($LabelStatus, "Status: Downloading... " & $percent & "%")
   EndIf
   $streamcounter = 0
  EndIf
  $streamcounter = $streamcounter + 1
WEnd
GUICtrlSetData($ProgressBar, 100)
GUICtrlSetState($DownloadButton, $GUI_ENABLE)
GUICtrlSetData($LabelStatus, "Status: Ready")

With StringReplace and StringStripWS remove all the .... and the space, and work. But for another commandline not work :)

Output example:

Connecting ...
Starting download at: 0.000 kB
Metadata:
  duration            11030.68
  moovPosition        32.00
  width              640.00
  height                480.00
  videocodecid        avc1
  audiocodecid        mp4a
  avcprofile            100.00
  avclevel            31.00
  aacaot                2.00
  videoframerate        25.00
  audiosamplerate      48000.00
  audiochannels      2.00
trackinfo:
  length                1103064.00
  timescale          100.00
  language            und
sampledescription:
  sampletype            avc1
  length                529472512.00
  timescale          48000.00
  language            und
sampledescription:
  sampletype            mp4a
399.301 kB / 9.28 sec (0.0%)

So i have make:

GUICtrlSetData($ProgressBar, 0)
$CMDDir = $soft & " -r" & " " & $URL & " " & "-o " & '"' & @WorkingDir & "video.flv" & '"'
$CMDCommand = Run($CMDDir, @ScriptDir, @SW_HIDE, $STDERR_CHILD)
ProcessSetPriority($CMDCommand, 0) ;; lowest
$streamcounter = 0
While ProcessExists($CMDCommand)
  If 1 <= $streamcounter Then
   $readstream = StderrRead($CMDCommand)
   $percent = _StringBetween($readstream, "sec (", "%)")
   If @error <> 1 Then
    GUICtrlSetData($LabelStatus, "Status: Downloading... " & $percent & "%")
    GUICtrlSetData($ProgressBar, $percent) ;; progress bar
   EndIf
   $streamcounter = 0
  EndIf
  $streamcounter = $streamcounter + 1
WEnd
GUICtrlSetData($ProgressBar, 100)
GUICtrlSetState($DownloadButton, $GUI_ENABLE)
GUICtrlSetData($LabelStatus, "Status: Ready)

Status is always ready, i can't understand why.

Please a little help ;)

Thanks for support

Edited by johnmcloud
Link to comment
Share on other sites

All command line tools don't give output in same way.

You need to adapt case by case...

You have right, but the second don't give me any output on autoit

$readstream = StdoutRead($CMDCommand)
ConsoleWrite($readstream)

Is empty :)

On classic CMD i see all information. What is the error?

Thanks

EDIT If i use StderrRead and ConsoleWrite, i can see on Console this:

Connecting ...
Starting download at: 0.000 kB
Metadata:
  duration            11030.68
  moovPosition        32.00
  width              640.00
  height                480.00
  videocodecid        avc1
  audiocodecid        mp4a
  avcprofile            100.00
  avclevel            31.00
  aacaot                2.00
  videoframerate        25.00
  audiosamplerate      48000.00
  audiochannels      2.00
trackinfo:
  length                1103064.00
  timescale          100.00
  language            und
sampledescription:
  sampletype            avc1
  length                529472512.00
  timescale          48000.00
  language            und
sampledescription:
  sampletype            mp4a
0.510 kB / 0.00 sec (0.0%)
132.559 kB / 2.40 sec (0.0%)
399.301 kB / 9.28 sec (0.0%)
590.328 kB / 12.28 sec (0.1%)
984.498 kB / 19.12 sec (0.1%)

But the progress bar and the label say 0, i don't know why...

Edited by johnmcloud
Link to comment
Share on other sites

Ok, guys, i can figure out how to adapt to another command line.

But i have two problem

1) I can't stop it, during download when i click on close button nothing happens. I have try to make a button with ProcessClose but nothing

2) I don't know how to make a error msgbox in the script

Thanks for support

Link to comment
Share on other sites

Ok, guys, i can figure out how to adapt to another command line.

But i have two problem

1) I can't stop it, during download when i click on close button nothing happens. I have try to make a button with ProcessClose but nothing

2) I don't know how to make a error msgbox in the script

Thanks for support

It will be more easy to help you if you show your code... :)

AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...