Jump to content

Recommended Posts

Posted
Local $iPID = Run(@ComSpec & ' /c rclone.exe --config=rclone.conf sync -P --create-empty-src-dirs 7days:/mods ./mods', @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Local $sConsole
    Do
        $sConsole &= StdoutRead($iPID)
    If @error Then ExitLoop

    $resul = StringRegExp($sConsole, "\h*\d+%", 3)
    ;Local $result = $resul[0]
    ConsoleWrite($result)
    Until Not Sleep(10)
    ExitLoop

I am trying to regexp against the follwing line

 

Quote

Transferred:      243.269M / 3.341 GBytes, 7%, 72.603 MBytes/s, ETA 43s

My RegExp should get the % shown in the output but instead Consolewrite only returns  1 repeatedly in the consolle output

Posted

Your Regex works fine, me thinks:

$sConsole = "Transferred:      243.269M / 3.341 GBytes, 7%, 72.603 MBytes/s, ETA 43s"
$result = StringRegExp($sConsole, "\h*\d+%", 3)
ConsoleWrite("Result: " & $result[0] & @CRLF)

Text from console Output:  "Result:  7%"

 

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Posted (edited)

Try changing your regex line to this and see what you get:

$resul = StringRegExp($sConsole, ".*\b(\d+%)", 1)

But make sure you keep $result[0] in the consolewrite()

 

You are concatenating (&=) the output into $sConsole each time thru the loop.  So each time thru the loop you are getting the same message over and over again with ()hopefully) a different percentage.  So you want the last percentage found in the string, not the first.

Try doing a ConsoleWrite() of $sConsole inside the loop to see what its content is.

Edited by TheXman
Posted (edited)

Show your code!

You should check to see if you found any results.  You have no error checking.

At a minimum, at least check to see that you have a valid array  returned from StringRegExp:

If IsArray($aResult) Then ConsoleWrite("Result: " & $aResult[0] & @CRLF)

 

Edited by TheXman
Posted
#include <Constants.au3>

    Local $iPID = Run(@ComSpec & ' /c rclone.exe --config=rclone.conf sync -P --create-empty-src-dirs 7days:/mods ./mods', @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Sleep(60)
    Local $sConsole, $aResult
    Do
        $sConsole &= StdoutRead($iPID)
        If @error Then ExitLoop
        $aResult = StringRegExp($sConsole, ".*\b(\d+%)", 1)
        ConsoleWrite("Result: " & $aResult[0] & @CRLF)
    Until Not Sleep(10)

 

Posted

Just for Informaation,

 

Is this method even able to read a stdout that is not a fixed string.

rclone works like rsync and allowes for syncing files with cloud hosters. I want to call rysnc in background and show its syncing process later in a gui

 

Posted (edited)

Since I haven't tried to capture the progress of rclone or rsync, from stdout, in a script, all I can see is that I think it's possible.  If it writes to the console like 7z, then it's possible.  I saw that you looked at 7zip progress bar topic.  You can use that as an example.

Edited by TheXman
Posted

Did you try writing out the content of $sConsole within the loop, as I suggested, so you can actually see what is being read from stdout?

Posted

Yes the $sConsole is readable with the content I need.

 

Quote

Transferred:           3.561M / 3.341 GBytes, 0%, 8.827 MBytes/s, ETA 6m27s
Transferred:            0 / 1, 0%
Elapsed time:         0.7s
Transferring:
 *                                 mods-full.zip:  0% /3.341G, 0/s, -Transferred:           3.561M / 3.341 GBytes, 0%, 8.827 MBytes/s, ETA 6m27s
Transferred:            0 / 1, 0%
Elapsed time:         0.7s
Transferring:
 *                                 mods-full.zip:  0% /3.341G, 0/s, -Transferred:           3.561M / 3.341 GBytes, 0%, 8.827 MBytes/s, ETA 6m27s
Transferred:            0 / 1, 0%
Elapsed time:         0.7s
Transferring:
 *                                 mods-full.zip:  0% /3.341G, 0/s, -Transferred:           3.561M / 3.341 GBytes, 0%, 8.827 MBytes/s, ETA 6m27s
Transferred:            0 / 1, 0%
Elapsed time:         0.7s
Transferring:
 *                                 mods-full.zip:  0% /3.341G, 0/s, -Transferred:           3.561M / 3.341 GBytes, 0%, 8.827 MBytes/s, ETA 6m27s
Transferred:            0 / 1, 0%
Elapsed time:         0.7s
Transferring:
 *                                 mods-full.zip:  0% /3.341G, 0/s, -Transferred:           3.561M / 3.341 GBytes, 0%, 8.827 MBytes/s, ETA 6m27s
Transferred:            0 / 1, 0%
Elapsed time:         0.7s
Transferring:
 *                                 mods-full.zip:  0% /3.341G, 0/s, -Transferred:           3.561M / 3.341 GBytes, 0%, 8.827 MBytes/s, ETA 6m27s
Transferred:            0 / 1, 0%
Elapsed time:         0.7s

 

Posted

This should work:

#include <Constants.au3>

Local $iPID = Run(@ComSpec & ' /c rclone.exe --config=rclone.conf sync -P --create-empty-src-dirs 7days:/mods ./mods', @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

Sleep(60)
Local $sConsole

Do
   $sConsole &= StdoutRead($iPID)
Until @Error And Sleep(10)

$result = StringRegExp($sConsole, "\h*\d+%", 3)

if IsArray($result) Then
   ConsoleWrite("Result: " & $result[0] & @CRLF)
Else
   ConsoleWrite("No Results Found:" & @CRLF)
EndIf

 

Code hard, but don’t hard code...

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
  • Recently Browsing   0 members

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