GUI에서 rsync 진행 상황을 래핑하는 가장 좋은 방법은 무엇입니까?
-
08-06-2019 - |
문제
나는 사용한다 재동기화 서버에 구애받지 않는 방식으로 Windows 클라이언트에 파일을 동기화합니다.GUI 진행률 표시줄에 표시하기 위해 rsync 진행 상황을 상위 프로세스로 보내는 데 사용할 수 있는 방법은 무엇입니까?
나는 두세 가지 선택이 존재한다고 상상한다.(1) STDOUT 보기 (2) unix와 유사한 rsync.exe 로그 파일 보기 tail
(3) 메모리에서 rsync 콘솔 출력을 관찰합니다.
어느 것이 가장 좋고/선호되나요?
해결책
이러한 유형의 작업에는 내 자신의 오토잇 스크립트(프리웨어, Windows에만 해당)스크립트는 표준 출력을 그래픽 창으로 리디렉션하여 뒤로 스크롤할 수 있는 기능 등을 표시합니다(XCOPY/PKZIP과 같은 긴 프로세스에서 오류가 발생했는지 확인하는 데 매우 유용합니다).
AutoIt은 무료이고, 사용하기 매우 쉽고, .EXE로 빠르게 컴파일할 수 있기 때문에 사용합니다.저는 이것이 이러한 유형의 작업을 위한 완전한 프로그래밍 언어에 대한 훌륭한 대안이라고 생각합니다.단점은 Windows 전용이라는 점입니다.
$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
다른 팁
.NET에는 STDOUT을 읽고 보는 매우 간단한 방법이 있습니다.
나는 이것이 외부 파일에 의존하지 않고 rsync 경로에만 의존하기 때문에 가장 깨끗한 방법이라고 생각합니다.거기에 래퍼 라이브러리가 있다고 해도 별로 놀라지 않을 것입니다.그렇지 않은 경우 작성하고 소스를 공개하세요 :)
나는 이를 위해 나만의 간단한 개체를 만들었습니다. 이를 통해 많은 재사용이 가능합니다. cmdline
, web page
, webservice
, 파일에 출력 쓰기 등---
댓글 항목에는 일부 내용이 포함되어 있습니다. rsync
예--
내가 언젠가 하고 싶은 일은 삽입하는 거야 rsync
(그리고 cygwin
)을 리소스로 변환하고 단일 .net 실행 파일을 만듭니다.--
여기 있습니다:
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
확인해 보세요 델타복사.rsync용 Windows GUI입니다.
확인하다 NAS백업 Watch STDOUT을 사용하여 Windows 사용자에게 Rsync GUI를 제공하는 오픈 소스 소프트웨어입니다.