Jump to content

strange scripting problem


yucatan
 Share

Recommended Posts

hello guys i have made a script that reads out a dos box and log that into a gui

its a gui controling the program rsync

when i connect to sync server 127.0.0.1 (my own computer ofcourse) its connects and start making backups

but if i change the ip so 177.0.0.1(a fake ip adres it does not exsist) i wanted to know what happens if it cannot connect.

what happening is the following in my console i see:

rsync: failed to connect to 177.0.0.1: Connection timed out (116)

rsync error: error in socket IO (code 10) at /home/lapo/packaging/rsync-3.0.4-1/src/rsync-3.0.4/clientserver.c(122) [sender=3.0.4]

the problem is that i just cannot understand how i can get in my console i'm searching in my code to find how its possible that it shows up in my console

i wanne be able to store that in a variable but i cannot discover how it gets in my console. can somebody help me pleas

here is my code

#Include <GuiListbox.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <Array.au3>
$sCmd = "rsync -vrtz --delete --progress /cygdrive/c/test2 177.0.0.1::asecretpwd"  ; Test command
$dir =  "C:/test2"
$size = DirGetSize($dir)
$npid = Run($scmd, @ScriptDir, @SW_hide, "0x2")
$nAutoTimeout = 10      ; Time in seconds to close window after finish
$nDeskPct = 60          ; % of desktop size (if percent)
$text = ""
$days = ""
; $nHeight = 480          ; height/width of the main window (if fixed)
; $nWidth = 480

$sTitRun = "Executing process. Wait...."     ; 
$sTitDone = "Process done"                ; 

$sSound = @WindowsDir & "\Media\Ding.wav"       ; End Sound

$sButRun = "Cancel"                           ; Caption of "Exec" button
$sButDone = "Close"                            ; Caption of "Close" button


Opt("GUIOnEventMode", 1)

if $nDeskPct > 0 Then
    $nHeight = @DesktopHeight * ($nDeskPct / 100)
    $nWidth = @DesktopWidth * ($nDeskPct / 100)
EndIf


If $CmdLine[0] > 0 Then
    $sCmd = ""
    For $nCmd = 1 To $CmdLine[0]
        $sCmd = $sCmd & " " & $CmdLine[$nCmd]
    Next
EndIf

; AutoItSetOption("GUIDataSeparatorChar", Chr(13)+Chr(10))

$nForm = GUICreate($sTitRun, $nWidth, $nHeight)
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseForm")

$nList = GUICtrlCreateList ("", 10, 200, $nWidth - 20, $nHeight - 250, $WS_BORDER + $WS_VSCROLL)
GUICtrlSetFont (-1, 9, 0, 0, "Courier New")

$nClose = GUICtrlCreateButton ($sButRun, $nWidth - 100, $nHeight - 40, 80, 30)
GUICtrlSetOnEvent (-1, "CloseForm")

GUISetState(@SW_SHOW)   ;, $nForm)
While 1
    $sLine = StdoutRead($nPID)
    $text &= $sline&@CRLF     
   If @error Then ExitLoop


if StringLen ($sLine) > 0 then
     
       $sLine = StringReplace ($sLine, Chr(13), "|")
        $sLine = StringReplace ($sLine, Chr(10), "")
        if StringLeft($sLine, 1)="|" Then
            $sLine = " " & $sLine
        endif
if $days = "" then $days = StringSplit($sline, " ")


        GUICtrlSetData ($nList, $sLine)
        
        
        _GUICtrlListBox_SetCurSel ($nList, _GUICtrlListBox_GetCount ($nList) - 1)
   EndIf
Wend








;-------------------
$sLine = " ||"
GUICtrlSetData ($nList, $sLine)
_GUICtrlListBox_SetCurSel ($nList, _GUICtrlListBox_GetCount ($nList) - 1)

GUICtrlSetData ($nClose, $sButDone)

WinSetTitle ($sTitRun, "", $sTitDone)
If $sSound <> "" Then
    SoundPlay ($sSound)
EndIf

$rInfo = DllStructCreate("uint;dword")      ; # LASTINPUTINFO
DllStructSetData($rInfo, 1, DllStructGetSize($rInfo));

DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($rInfo))
$nLastInput = DllStructGetData($rInfo, 2)

$nTime = TimerInit()

While 1
    If $nAutoTimeout > 0 Then
        DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($rInfo))
        If DllStructGetData($rInfo, 2) <> $nLastInput Then
            ; Tocó una tecla
            $nAutoTimeout = 0
        EndIf
    EndIf

    If $nAutoTimeout > 0 And TimerDiff ($nTime) > $nAutoTimeOut * 1000 Then
        ExitLoop
    EndIf

    Sleep (100)
Wend


Func CloseForm()
    
    Exit
EndFunc
Link to comment
Share on other sites

Here is an example which might help you. I have no idea who wrote it. It might be something I modified from the help for StdoutRead.

#include <Constants.au3>

While 1
    $data = ''
    $instr = InputBox("DOS commander", "next command")
    If $instr = '' Then Exit

    Local $foo = Run("cmd.exe", @SystemDir, @SW_HIDE, 9);$STDIN_CHILD + $STDOUT_CHILD)cmd.exe
    StdinWrite($foo, $instr & @CRLF);& "cat" & @CRLF & "bat" & @CRLF)
    ; Calling with no 2nd arg closes stream
    StdinWrite($foo)

    ; Read from child's STDOUT and show
    Local $data
    While True
        $data &= StdoutRead($foo)
        If @error Then ExitLoop
        Sleep(25)
    WEnd
    MsgBox(0, "DOS output", $data)
WEnd
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Here is an example which might help you. I have no idea who wrote it. It might be something I modified from the help for StdoutRead.

#include <Constants.au3>

While 1
    $data = ''
    $instr = InputBox("DOS commander", "next command")
    If $instr = '' Then Exit

    Local $foo = Run("cmd.exe", @SystemDir, @SW_HIDE, 9);$STDIN_CHILD + $STDOUT_CHILD)cmd.exe
    StdinWrite($foo, $instr & @CRLF);& "cat" & @CRLF & "bat" & @CRLF)
    ; Calling with no 2nd arg closes stream
    StdinWrite($foo)

    ; Read from child's STDOUT and show
    Local $data
    While True
        $data &= StdoutRead($foo)
        If @error Then ExitLoop
        Sleep(25)
    WEnd
    MsgBox(0, "DOS output", $data)
WEnd

sorry mate but thats not the answer to my question i asked why when the connection fails it shows up in console

thx for the sample but i cannot use it. maby somebody else know the answer to my question.

thx

Link to comment
Share on other sites

sorry mate but thats not the answer to my question i asked why when the connection fails it shows up in console

thx for the sample but i cannot use it. maby somebody else know the answer to my question.

thx

Do you mean that when it fails a new console window opens with a message in it?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Do you mean that when it fails a new console window opens with a message in it?

martin i shall show u whats going wrong

this is the code i use now

#Include <GuiListbox.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <Array.au3>
$sCmd = "rsync -vrtz --delete --progress /cygdrive/c/test2 177.0.0.1::asecretpwd"  ; Test command
$dir =  "C:/test2"
$size = DirGetSize($dir)
$npid = Run($scmd, @ScriptDir, @SW_hide, "0x2")
$nAutoTimeout = 10      ; Time in seconds to close window after finish
$nDeskPct = 60          ; % of desktop size (if percent)
$text = ""
$days = ""
; $nHeight = 480          ; height/width of the main window (if fixed)
; $nWidth = 480

$sTitRun = "Executing process. Wait...."     ; 
$sTitDone = "Process done"                ; 

$sSound = @WindowsDir & "\Media\Ding.wav"       ; End Sound

$sButRun = "Cancel"                           ; Caption of "Exec" button
$sButDone = "Close"                            ; Caption of "Close" button


Opt("GUIOnEventMode", 1)

if $nDeskPct > 0 Then
    $nHeight = @DesktopHeight * ($nDeskPct / 100)
    $nWidth = @DesktopWidth * ($nDeskPct / 100)
EndIf


If $CmdLine[0] > 0 Then
    $sCmd = ""
    For $nCmd = 1 To $CmdLine[0]
        $sCmd = $sCmd & " " & $CmdLine[$nCmd]
    Next
EndIf

; AutoItSetOption("GUIDataSeparatorChar", Chr(13)+Chr(10))

$nForm = GUICreate($sTitRun, $nWidth, $nHeight)
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseForm")

$nList = GUICtrlCreateList ("", 10, 200, $nWidth - 20, $nHeight - 250, $WS_BORDER + $WS_VSCROLL)
GUICtrlSetFont (-1, 9, 0, 0, "Courier New")

$nClose = GUICtrlCreateButton ($sButRun, $nWidth - 100, $nHeight - 40, 80, 30)
GUICtrlSetOnEvent (-1, "CloseForm")

GUISetState(@SW_SHOW)   ;, $nForm)
While 1
    $sLine = StdoutRead($nPID)
    $text &= $sline&@CRLF     
   If @error Then ExitLoop


if StringLen ($sLine) > 0 then
     
       $sLine = StringReplace ($sLine, Chr(13), "|")
        $sLine = StringReplace ($sLine, Chr(10), "")
        if StringLeft($sLine, 1)="|" Then
            $sLine = " " & $sLine
        endif
if $days = "" then $days = StringSplit($sline, " ")


        GUICtrlSetData ($nList, $sLine)
        
        
        _GUICtrlListBox_SetCurSel ($nList, _GUICtrlListBox_GetCount ($nList) - 1)
   EndIf
Wend








;-------------------
$sLine = " ||"
GUICtrlSetData ($nList, $sLine)
_GUICtrlListBox_SetCurSel ($nList, _GUICtrlListBox_GetCount ($nList) - 1)

GUICtrlSetData ($nClose, $sButDone)

WinSetTitle ($sTitRun, "", $sTitDone)
If $sSound <> "" Then
    SoundPlay ($sSound)
EndIf

$rInfo = DllStructCreate("uint;dword")      ; # LASTINPUTINFO
DllStructSetData($rInfo, 1, DllStructGetSize($rInfo));

DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($rInfo))
$nLastInput = DllStructGetData($rInfo, 2)

$nTime = TimerInit()

While 1
    If $nAutoTimeout > 0 Then
        DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($rInfo))
        If DllStructGetData($rInfo, 2) <> $nLastInput Then
            ; Tocó una tecla
            $nAutoTimeout = 0
        EndIf
    EndIf

    If $nAutoTimeout > 0 And TimerDiff ($nTime) > $nAutoTimeOut * 1000 Then
        ExitLoop
    EndIf

    Sleep (100)
Wend


Func CloseForm()
    
    Exit
EndFunc

i have added 2 screenshots one screenshot that i filled in the good ipadress in the command line and then i connect and start to stransfer

the other screenshot u see that the gui display stays emty and it gives the error in the console and i cant figure out why that is because i want to be able to catch that error and use it as a variable in autoit. pleas somebody help me thx!!!

the other screenshot was to big to upload here see link: http://img269.imageshack.us/img269/8838/ipwrong.jpg

post-33750-12560733059912_thumb.jpg

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

  • Recently Browsing   0 members

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