Jump to content

Recommended Posts

Posted

Hello, I'm having trouble getting output from run() ing a command that takes quite a while to get it's output. My problem is that I have a slow internet connection, am downloading a large file that errors out after a while and so I want to script it so I don't have to restart it over and over again.

I'm trying to cycle through a series of web sites to retrieve a file, only going to the next site if a previous one fails. Any help would be appreciated, thanks.

#include <Constants.au3>
#include <Array.au3>

dim $array[9], $i, $bt3b

$Array[0]= "//ftp://ftp.heanet.ie/mirrors/backtrack/bt3b141207.rar"
$Array[1]= "//ftp://ftp.cc.uoc.gr/mirrors/linux/backtrack/bt3b141207.rar"
$Array[2]= "//http://ftp.cc.uoc.gr/mirrors/linux/backtrack/bt3b141207.rar"
$Array[3]= "//http://mirror.switch.ch/ftp/mirror/backtrack/bt3b141207.rar"
$Array[4]= "//ftp://backtrack.mirrors.skynet.be/pub/backtrack/bt3b141207.rar"
$Array[5]= "//http://backtrack.unixheads.org/bt3b141207.rar"
$Array[6]= "//http://ftp.heanet.ie/mirrors/backtrack/bt3b141207.rar"
$Array[7]= "//http://ftp.belnet.be/mirror/backtrack/bt3b141207.rar"
$Array[8]= "//http://backtrack.mirrors.skynet.be/pub/backtrack/bt3b141207.rar"

;http://www.remote-exploit.org/bt3b141207.rar.torrent

$i = 0

while $i < 9
  $bt3b= Run(@ComSpec & " /c " & $array[$i], "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

  While 1
    $line = StdoutRead($bt3b)
   ;possible errors
     ;HTTP request sent, awaiting response
     ;Giving up
    If stringinstr($line, "Giving up") Then 
      $i = $i + 1
      $line = ""
      $bt3b = ""
      exitloop
    endif   
  Wend
wend
Posted

I have something similar for an auto-update program I wrote.

;Generic Download Plugin Template v3 Update 10/9/2007

;The following command is only for execution of this plugin directly, for testing

;Include functions for log file
#include <file.au3>

;Don't change this path as it is harcoded in Assembler
Const $DEST = @ScriptDir & "\Files\"
Const $LOG = @ScriptDir & "\plugin.log"

;MsgBox(0,"",$DEST & @CRLF & $LOG)

;Retrieve mirrors
$MIRRORS = IniReadSection (@ScriptDir & "\config.ini", "Mirrors" )

;Retrieve filename from first mirror
$SPLITMIRROR = StringSplit ( $MIRRORS[1][1], "/")
$FILENAME = $SPLITMIRROR[$SPLITMIRROR[0]]

;Attempt download if file is not found
If NOT FileExists ($DEST & $FILENAME) Then

    _FileWriteLog($LOG,"File not found: " & $FILENAME)

    ;Loop through mirrors
    For $i = 1 To $MIRRORS[0][0]
        _FileWriteLog($LOG,"Trying: " & $MIRRORS[$i][1])
        
        ;Set default window mode
        $SW = @SW_SHOW
        If ($CmdLine[0] AND $CmdLine[1] = "S") Then $SW = @SW_HIDE
        
        ;Download file via cygwin wget, run silent if parameter is found
        ;$EXITCODE = RunWait("wget.exe -N " & $MIRRORS[$i][1], $DEST, $SW)
        $result = InetGet ($MIRRORS[$i][1], $DEST & $FILENAME)
        
        ;If download successful break loop
        If $result Then
            _FileWriteLog($LOG,"Download complete - " & $MIRRORS[$i][1])    
            ExitLoop
        EndIf
    Next
EndIf

;If file missing exit with errorlevel
If NOT FileExists ($DEST & $FILENAME) Then
    _FileWriteLog($LOG,"ERROR")
    Exit (1)
EndIf
    
_FileWriteLog($LOG,"OK")
Exit (0)

config.ini:

[Main]
Name=7-Zip
Enabled=Yes
Version=4.42
License=Freeware
Updated=2007/10/08 20:16:11
Destination=WINFILES\File Compression\7-Zip

[Menu]
path=File Compression
command=7z442.exe
oscode=255

[Mirrors]
0=http://easynews.dl.sourceforge.net/sourceforge/sevenzip/7z442.exe
1=http://somesite/sourceforge/sevenzip/7z442.exe
2=http://anothersite/sourceforge/sevenzip/7z442.exe
Posted

I've also tried this, but I'll check your code out too, thanks weaponx

#include <Constants.au3>
#include <Array.au3>

dim $array[9], $i; $bt3b

$Array[0]= "//ftp://ftp.heanet.ie/mirrors/backtrack/bt3b141207.rar"
$Array[1]= "//ftp://ftp.cc.uoc.gr/mirrors/linux/backtrack/bt3b141207.rar"
$Array[2]= "//http://ftp.cc.uoc.gr/mirrors/linux/backtrack/bt3b141207.rar"
$Array[3]= "//http://mirror.switch.ch/ftp/mirror/backtrack/bt3b141207.rar"
$Array[4]= "//ftp://backtrack.mirrors.skynet.be/pub/backtrack/bt3b141207.rar"
$Array[5]= "//http://backtrack.unixheads.org/bt3b141207.rar"
$Array[6]= "//http://ftp.heanet.ie/mirrors/backtrack/bt3b141207.rar"
$Array[7]= "//http://ftp.belnet.be/mirror/backtrack/bt3b141207.rar"
$Array[8]= "//http://backtrack.mirrors.skynet.be/pub/backtrack/bt3b141207.rar"

$i = 0
while $i < 9

InetGet($array[$i], "bt3b.rar", 1, 1)

While @InetGetActive
  TrayTip("Downloading", "Bytes = " & @InetGetBytesRead, 10, 16)
  Sleep(250)
Wend

if @InetGetBytesRead = -1 then
  $i = $i + 1
  continueloop
endif

wend

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...