1

I'm using start to run a command from a batch file.

SET mycmd=SOME_CMD WITH ARGS
START "Demo" %mycmd%

This works fine, and the resulting cmd window persists after executing the contents of mycmd, even if the batch file was double-clicked - the reason why I'm using start to begin with.

However I would also like to print something in the new cmd window that start opens, before it runs the command.

I'd imagine that I would pass start an echo command, followed by the command I want it to run.


My first naive approach was as follows:

SET mycmd=SOME_CMD WITH ARGS
START "Demo" ECHO Running Command... && %mycmd%

Of course this does not work; start opens a new window which only runs the echo command, and the command after the && divider is run in the original window, not in the new one that the echo ran in.

Basically it performs (start echo) && (my_cmd) instead of start (echo && my_cmd) - parentheses added for clarity, not any actual syntactic meaning


So my question is: Is there a way to pass two commands to start at once? Specifically, I really just want it to echo out some content, and then run a command.

Johannes
  • 6,232
  • 9
  • 43
  • 59
  • Possible duplicate of [Batch character escaping](https://stackoverflow.com/questions/6828751/batch-character-escaping) – phuclv Jan 11 '18 at 06:19
  • [Special Characters in Batch File](https://stackoverflow.com/q/37333620/995714) – phuclv Jan 11 '18 at 06:20

1 Answers1

3

Change && to ^& to escape a single & which then cascades the echo with your command.

Magoo
  • 77,302
  • 8
  • 62
  • 84