windows – 在gui中包装rsync进度的最佳方法?
发布时间:2020-08-03 13:22:43  所属栏目:Windows  来源:互联网 
            导读:我使用 rsync以与服务器无关的方式将文件同步到Windows客户端.有什么方法可以将rsync的进度发送到父进程以在gui进度条中显示? 我想有两三种选择. (1)监视STDOUT(2)监视rsync.exe日志文件,类似于unix tail(3)在内存中监视rsync控制台输出. 哪一个最好/首选?
                
                
                
            | 
                         我使用 rsync以与服务器无关的方式将文件同步到Windows客户端.有什么方法可以将rsync的进度发送到父进程以在gui进度条中显示? 我想有两三种选择. (1)监视STDOUT(2)监视rsync.exe日志文件,类似于unix tail(3)在内存中监视rsync控制台输出. 哪一个最好/首选? 对于这种类型的任务,我使用自己的 AutoIt脚本(免费软件,仅限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 & "MediaDing.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,$nWidth - 20,$nHeight - 50,$WS_BORDER + $WS_VSCROLL)
GUICtrlSetFont (-1,9,"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,$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",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                        (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!  | 
                  
相关内容
- windows – 批处理 – 将命令输出存储到变量(多行)
 - Windows调试器路线图
 - windows-nginx-https-本地配置
 - windows下mysql主从复制配置
 - 开发了一款写作软件(OSX,Windows),附带Electron开发指南
 - .net – System.Windows.Input.Key枚举中的Equals键没有条目
 - 无法找到MSVCP120D.DLL或0x00007启动错误的解决方法
 - cmd – 如何为特定应用程序强制传出ip? ForceBindIp似乎不
 - xaml – Windows 8 App,更改BackButtonStyle的颜色
 - IE11 For Win7、win2008中文版官方下载地址
 
