2008-08-11 23 views
5

Dosyaları Windows istemcilerine bir sunucuyla senkronize şekilde senkronize etmek için rsync kullanıyorum. Bir gui ilerleme çubuğunda görüntülemek için ana sürecin rsync'in ilerlemesini göndermek için hangi yöntemler kullanılabilir?Bir gui'de rsync ilerlemesini sarmanın en iyi yolu?

İki veya üç seçenek bulunduğunu hayal ediyorum. (1) Watch STDOUT (2) unix tail'a benzer rsync.exe günlük dosyasını izleyin (3) Hafızadaki rsync konsol çıkışını izleyin.

Hangisi en iyisi/tercih edilir?

cevap

2

Bu tür görevler için, kendi AutoIt komut dosyasını kullanıyorum (ücretsiz, yalnızca Windows). Komut dosyası standart çıktısını grafiksel bir pencereye yeniden yönlendirerek, geriye kaydırma yeteneği ile göstererek (herhangi bir hatanın gerçekleşip gerçekleşmediğini kontrol etmek için XCOPY/PKZIP gibi uzun süreçlerde çok kullanışlıdır).

Ücretsiz, kullanımı çok kolay ve hızlı bir şekilde bir .exe halinde derleyebildiğim için AutoIt kullanıyorum. Bu tür görevler için eksiksiz bir programlama diline mükemmel bir alternatif olduğunu düşünüyorum. Olumsuz tarafı sadece Windows için olmasıdır.

$sCmd = "DIR E:\*.AU3 /S" ; Test command 
$nAutoTimeout = 10  ; Time in seconds to close window after finish 

$nDeskPct = 60   ; % of desktop size (if percent) 

; $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 

#include <GUIConstants.au3> 
#include <Constants.au3> 
#Include <GuiList.au3> 

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 

    ; MsgBox (1,"",$sCmd) 
EndIf 

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

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

$nList = GUICtrlCreateList ("", 10, 10, $nWidth - 20, $nHeight - 50, $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) 

$nPID = Run(@ComSpec & " /C " & $sCmd, ".", @SW_HIDE, $STDOUT_CHILD) 
; $nPID = Run(@ComSpec & " /C _RunErrl.bat " & $sCmd, ".", @SW_HIDE, $STDOUT_CHILD)  ; # Con ésto devuelve el errorlevel en _ERRL.TMP 

While 1 
    $sLine = StdoutRead($nPID) 
    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 

     GUICtrlSetData ($nList, $sLine) 

     _GUICtrlListSelectIndex ($nList, _GUICtrlListCount ($nList) - 1) 
    EndIf 
Wend 

$sLine = " ||" 
GUICtrlSetData ($nList, $sLine) 
_GUICtrlListSelectIndex ($nList, _GUICtrlListCount ($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 
1

.NET, STDOUT'u okumak ve izlemek için oldukça basit bir yol sunuyor.
Bu en temiz yol olurdu, çünkü herhangi bir harici dosyaya bağlı değil, sadece rsync'e giden yol. Orada da bir sarmalayıcı kütüphanesi varsa çok şaşırmam. Değilse, yazın ve kaynak açın :)

1

ben, vs, bir cmdline, web page, webservice ile sarın çıktıyı bir dosyaya yazabilir, ben bunun dışında yeniden kullanımı çok olsun, bunun için kendi basit nesne inşa ettik ---

yorumladı ürün I bazen yapmak istediğim şey rsync examples--

bir kaynak & içine rsync (ve cygwin) gömmek bazı tek .net yürütülebilir

dökersin-- dışına yapmak içerirler Burada

gitmek:

Imports System.IO 

Namespace cds 

Public Class proc 

    Public _cmdString As String 
    Public _workingDir As String 
    Public _arg As String 


    Public Function basic() As String 

     Dim sOut As String = "" 

     Try 
      'Set start information. 
      'Dim startinfo As New ProcessStartInfo("C:\Program Files\cwRsync\bin\rsync", "-avzrbP 192.168.42.6::cdsERP /cygdrive/s/cdsERP_rsync/gwy") 
      'Dim startinfo As New ProcessStartInfo("C:\Program Files\cwRsync\bin\rsync", "-avzrbP 10.1.1.6::user /cygdrive/s/cdsERP_rsync/gws/user") 
      'Dim startinfo As New ProcessStartInfo("C:\windows\system32\cscript", "//NoLogo c:\windows\system32\prnmngr.vbs -l") 

      Dim si As New ProcessStartInfo(_cmdString, _arg) 

      si.UseShellExecute = False 
      si.CreateNoWindow = True 
      si.RedirectStandardOutput = True 
      si.RedirectStandardError = True 

      si.WorkingDirectory = _workingDir 


      ' Make the process and set its start information. 
      Dim p As New Process() 
      p.StartInfo = si 

      ' Start the process. 
      p.Start() 

      ' Attach to stdout and stderr. 
      Dim stdout As StreamReader = p.StandardOutput() 
      Dim stderr As StreamReader = p.StandardError() 

      sOut = stdout.ReadToEnd() & ControlChars.NewLine & stderr.ReadToEnd() 

      'Dim writer As New StreamWriter("out.txt", FileMode.CreateNew) 
      'writer.Write(sOut) 
      'writer.Close() 

      stdout.Close() 
      stderr.Close() 
      p.Close() 


     Catch ex As Exception 

      sOut = ex.Message 

     End Try 

     Return sOut 

    End Function 

End Class 
End Namespace 
0

kontrol İzle STDOUT kullanarak Windows kullanıcı Rsync GUI vermek NAsBackup Onun açık kaynaklı yazılım.