Mic*_*gan 5 windows user-interface rsync
我使用rsync以与服务器无关的方式将文件同步到Windows客户端.有什么方法可以将rsync的进度发送到父进程以在gui进度条中显示?
我想有两三种选择.(1)监视STDOUT(2)监视rsync.exe日志文件,类似于unix tail(3)在内存中监视rsync控制台输出.
哪一个最好/首选?
对于此类任务,我使用自己的AutoIt脚本(免费软件,仅限 Windows)。该脚本将标准输出重定向到图形窗口,显示它并具有向后滚动的能力等(在 XCOPY / PKZIP 等长进程中非常有用,以检查是否发生任何错误)。
\n\n我使用 AutoIt 是因为它是免费的、非常易于使用,并且可以快速编译成 .EXE。我认为对于此类任务来说,它是完整编程语言的绝佳替代方案。缺点是它仅适用于 Windows。
\n\n$sCmd = "DIR E:\\*.AU3 /S" ; Test command\n$nAutoTimeout = 10 ; Time in seconds to close window after finish\n\n$nDeskPct = 60 ; % of desktop size (if percent)\n\n; $nHeight = 480 ; height/width of the main window (if fixed)\n; $nWidth = 480\n\n$sTitRun = "Executing process. Wait...." ; \n$sTitDone = "Process done" ; \n\n$sSound = @WindowsDir & "\\Media\\Ding.wav" ; End Sound\n\n$sButRun = "Cancel" ; Caption of "Exec" button\n$sButDone = "Close" ; Caption of "Close" button\n\n#include <GUIConstants.au3>\n#include <Constants.au3>\n#Include <GuiList.au3>\n\nOpt("GUIOnEventMode", 1)\n\nif $nDeskPct > 0 Then\n $nHeight = @DesktopHeight * ($nDeskPct / 100)\n $nWidth = @DesktopWidth * ($nDeskPct / 100)\nEndIf\n\n\nIf $CmdLine[0] > 0 Then\n $sCmd = ""\n For $nCmd = 1 To $CmdLine[0]\n $sCmd = $sCmd & " " & $CmdLine[$nCmd]\n Next\n\n ; MsgBox (1,"",$sCmd)\nEndIf\n\n; AutoItSetOption("GUIDataSeparatorChar", Chr(13)+Chr(10))\n\n$nForm = GUICreate($sTitRun, $nWidth, $nHeight)\nGUISetOnEvent($GUI_EVENT_CLOSE, "CloseForm")\n\n$nList = GUICtrlCreateList ("", 10, 10, $nWidth - 20, $nHeight - 50, $WS_BORDER + $WS_VSCROLL)\nGUICtrlSetFont (-1, 9, 0, 0, "Courier New")\n\n$nClose = GUICtrlCreateButton ($sButRun, $nWidth - 100, $nHeight - 40, 80, 30)\nGUICtrlSetOnEvent (-1, "CloseForm")\n\nGUISetState(@SW_SHOW) ;, $nForm)\n\n$nPID = Run(@ComSpec & " /C " & $sCmd, ".", @SW_HIDE, $STDOUT_CHILD)\n; $nPID = Run(@ComSpec & " /C _RunErrl.bat " & $sCmd, ".", @SW_HIDE, $STDOUT_CHILD) ; # Con \xc3\xa9sto devuelve el errorlevel en _ERRL.TMP\n\nWhile 1\n $sLine = StdoutRead($nPID)\n If @error Then ExitLoop\n\n If StringLen ($sLine) > 0 then\n $sLine = StringReplace ($sLine, Chr(13), "|")\n $sLine = StringReplace ($sLine, Chr(10), "")\n if StringLeft($sLine, 1)="|" Then\n $sLine = " " & $sLine\n endif\n\n GUICtrlSetData ($nList, $sLine)\n\n _GUICtrlListSelectIndex ($nList, _GUICtrlListCount ($nList) - 1)\n EndIf\nWend\n\n$sLine = " ||"\nGUICtrlSetData ($nList, $sLine)\n_GUICtrlListSelectIndex ($nList, _GUICtrlListCount ($nList) - 1)\n\nGUICtrlSetData ($nClose, $sButDone)\n\nWinSetTitle ($sTitRun, "", $sTitDone)\nIf $sSound <> "" Then\n SoundPlay ($sSound)\nEndIf\n\n$rInfo = DllStructCreate("uint;dword") ; # LASTINPUTINFO\nDllStructSetData($rInfo, 1, DllStructGetSize($rInfo));\n\nDllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($rInfo))\n$nLastInput = DllStructGetData($rInfo, 2)\n\n$nTime = TimerInit()\n\nWhile 1\n If $nAutoTimeout > 0 Then\n DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($rInfo))\n If DllStructGetData($rInfo, 2) <> $nLastInput Then\n ; Toc\xc3\xb3 una tecla\n $nAutoTimeout = 0\n EndIf\n EndIf\n\n If $nAutoTimeout > 0 And TimerDiff ($nTime) > $nAutoTimeOut * 1000 Then\n ExitLoop\n EndIf\n\n Sleep (100)\nWend\n\n\nFunc CloseForm()\n Exit\nEndFunc\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
4863 次 |
| 最近记录: |