2

I have to convert a batch script to PowerShell. I came across these few lines of code and I have no idea what they do. Could someone explain it, especially the echo statements and robocopy?

set logdir=D:\Internal\Log
set runlog=%logdir%\run.log
set roboexe=robocopy /NJH /XX /NP

echo ^<!-- 1>>%runlog% 2>&1 
echo Move-Copy -  %account% %Time:/=% 1>>%runlog% 2>&1
echo Found files for %account% IN 1>>%runlog% 2>&1

%roboexe% "%fromdir%" "%historydir%" %wildcard% 1>>%runlog%
0

1 Answer 1

3

echo in shell just prints output to the screen. The command also works in PowerShell, but it's really an alias of Write-Output, which sends output to the standard success stream/pipeline (which if there's nowhere else for it to go, is the console/screen by default).

Robocopy is an advanced copying utility. It has a range of abilities beyond the standard copy function of Windows. It is documented here.

To explain the tokens in this line:

echo ^<!-- 1>>%runlog% 2>&1

<, >, and >> are redirection operators. The ^ character escapes the < character so that it's being used literally rather than as a redirect. !-- are also just being printed literally I believe.

1>> is using the append redirect to send the append the standard output to file specified in %runlog%.

2>&1 redirects the error output stream to the standard output stream, so basically errors would also be written to the runlog.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Mark for quick response. What is meaning of numbers (1,2) in ECHO ^<!-- 1>>%runlog% 2>&1 ECHO Move-Copy - %account% %Time:/=% 1>>%runlog% 2>&1 in these lines
Edited my answer with what I think is the explanation but i'm not a batch expert.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.