Jump to content

use STDoutRead to log progress from robocopy


Recommended Posts

Hi,

 

Before i start i would like to say that i already used the forum search option, and yes there are a few topic talking about this. but in non of them i did found the answer to my solution .

Back to this topic.i am currently writing a script for move(sync) files for some servers we are migrating. most part of the script i already have working or know the solution for. but now i have come to the part where i am trying to log the process of robocopy. i know this can be done with the command STDoutRead.

The robocopy command will have to copy like 15gb of files all not more then 15kb in size. my feeling says that the first run will be a long one and that's why i want log the stream. this is for if something goes wrong. and a error is dected i want to make the script capable of sending me a notification or when ready or other functions.

my question?: how am i able the use STDoutRead to read(react) in real time.

i currently have the following, where i keep asking myself the question where i need to code for it to react in realtime.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------
#include <Array.au3>
; Script Start - Add your code below here
Local $syncPID, $output, $switch = 0
Local $sourcedir = '"C:\SrcFolder"'
Local $destdir = '"D:\DesFolder"'
Local $options = '/TEE /E /COPYALL /PURGE /COPY:DATO /V /TS /FP /NP'

$syncPID = Run (@ComSpec & " /c " & 'Robocopy.exe ' & $sourcedir & ' ' & $destdir & ' ' & $options, @ScriptDir, @SW_Hide, 2 )


While ProcessExists ( $syncPID )
$tempOutput =  StdoutRead($syncPID , True , False)
$output = StringSplit($tempOutput, @LF)
ConsoleWrite ( $output[0] )
WEnd

_ArrayDisplay($output)
Edited by lilx
Link to comment
Share on other sites

What do you mean by "read(react) in real time"?

You start RoboCopy by Run (doesn't wait until RoboCopy has finished) and then grab every message delivered by RoboCopy to StdOut.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

The example of the help say all, just add a variable for "react" in real time like if $line = $var Then

; Demonstrates StdoutRead()
#include <Constants.au3>

Local $foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
WEnd

While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
WEnd

MsgBox(0, "Debug", "Exiting...")
Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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