How do I start cmd.exe /k with multiple commands?

2019-07-09 04:51发布

问题:

Why doesn't the following code change the color and the title on cmd2? How, and what to do? The command changes color on cmd1, and sets the title on cmd2?

start cmd.exe /k TITLE TEST & color 02 & mode con: cols=160 lines=78 

回答1:

start "TEST" cmd.exe /k "TITLE TEST & color 02 & mode con: cols=160 lines=78"

Without quoting the command that the new cmd instance must execute, the & is interpreted as a command concatenation after the start and so it is executed in the first instance. With quotes, it is part of the command to execute in the second cmd instance.

Also, as the start command sees the first quoted argument as the tile of the window to start, and we are going to use quotes, it is necessary to include a title in the command (or "" for no title).