Oratorian Posted July 10, 2021 Share Posted July 10, 2021 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 Link to comment Share on other sites More sharing options...
Marc Posted July 10, 2021 Share Posted July 10, 2021 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) Link to comment Share on other sites More sharing options...
Oratorian Posted July 10, 2021 Author Share Posted July 10, 2021 But somehow that all goes to hell if he reads the output from stdout instead from a defined string. Link to comment Share on other sites More sharing options...
TheXman Posted July 10, 2021 Share Posted July 10, 2021 (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 July 10, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Oratorian Posted July 10, 2021 Author Share Posted July 10, 2021 Then I get Subscript used on non-accessible variable.: Link to comment Share on other sites More sharing options...
TheXman Posted July 10, 2021 Share Posted July 10, 2021 (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 July 10, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Oratorian Posted July 10, 2021 Author Share Posted July 10, 2021 #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) Link to comment Share on other sites More sharing options...
Oratorian Posted July 10, 2021 Author Share Posted July 10, 2021 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 Link to comment Share on other sites More sharing options...
TheXman Posted July 10, 2021 Share Posted July 10, 2021 (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 July 10, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Oratorian Posted July 10, 2021 Author Share Posted July 10, 2021 I used that as an example i used tha code by UEZ posted there, but somehow it works for neiither of the two programs. Link to comment Share on other sites More sharing options...
TheXman Posted July 10, 2021 Share Posted July 10, 2021 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? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Oratorian Posted July 10, 2021 Author Share Posted July 10, 2021 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 Link to comment Share on other sites More sharing options...
JockoDundee Posted July 11, 2021 Share Posted July 11, 2021 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... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now