Jump to content
Sign in to follow this  
lilx

use STDoutRead to log progress from robocopy

Recommended Posts

lilx

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

Share this post


Link to post
Share on other sites
water

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 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Terenz

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

 

Share this post


Link to post
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
Sign in to follow this  

×