-1

How can I write a batch file that runs cmd.exe, enters the partial command robocopy then waits for user input to complete and execute the robocopy command? It seems like it should be the simplest thing to do but no method I've tried enters the command in such a way as to hold and wait for user input and then successfully execute the completed robocopy command

For example:

@echo off
set var="robocopy "
cmd.exe %var%

appears to work but then, for example, user-inputting /? to bring up robocopy's info instead brings up cmd.exe's info

Another example:

@echo off
cmd /k robocopy

Runs robocopy with no destination/source folders or switches, then closes robocopy and waits for a new user-inputted command.

what I'm trying to do is have a batch file that when I click it a cmd window will open with the partial command robocopy already entered ready for me to complete the command with source/destination/switches and execute it with an enter key press - I use robocopy all day long so this would be a big time saver.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Artproject
  • 13
  • 2

1 Answers1

3

it's not possible in the way you seem to think. That would mean to mess with the keyboard buffer (was pretty common with the C64 back in those times, but it's not possible in (pure) batch).

But the following should give you a good start for automation. It assumes, you use the same parameters each time and just want to give it a source and a destination folder. Adjust to your needs (especially the params - I added /L to prevent it from unwanted actions while testing):

@echo off
set "command=robocopy"
set "params=/L /E /MOV /MT:12 /FP /log+:robocopy.log /TEE"
set /p "source=Enter Source: "
set /p "destin=Enter Destination: "
%command% "%source%" "%destin%" %params%

The cmd.exe or cmd.exe /k isn't necessary, until you want robocopy to work in a new window.

Stephan
  • 53,940
  • 10
  • 58
  • 91