Вопрос

I am modifying a batch script to move a directory from one place to another. In the batch code, there are these two lines. I don't understand the first parts

echo xcopy %SOURCE_FILE% %TARGET_FILE% /Y /Z /C /F 1>>"%logfile%" 2>&1

echo F|xcopy %SOURCE_FILE% %TARGET_FILE% /Y /Z /C /F 1>>"%logfile%" 2>&1

  1. Do these lines of code execute the copy or just write out to the log file? I ask this because the code currently copies, however, there is no line of xcopy without the echo in front.
  2. In line two what does F|xcopy mean?
  3. Other then the F|xcopy on the second line, what is the difference between the two?
Это было полезно?

Решение

The first writes the command it is about to execute to a log file, but does nothing useful.

The second actually executes XCOPY but answers the question that gets asked with the letter "F" presumably when XCOPY asks "Do you mean Files or Directories?"

Другие советы

|is a pipe-symbol. It passes the output from the command before to the command after.

So the result of echo F (which is F) to the xcopy-command. So if xopy asks the user for input, it gets "F".

Simple example:

echo . | pause

Try it, pause waits for a keystroke, but echo . deliveres this keystroke.

  1. just the report of what is to be done. better to use the /L switch on xcopy.

  2. echo f| means to reply to a potential prompt with "f". The prompt is going to be "is the destination a directory or a file" the response is "file"

  3. The first reports only, the second executes.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top