Launching multiple shell prompts from a single batch file

我的未来我决定 提交于 2020-01-25 02:55:09

问题


I have a set of DOS commands that I need to run in different shell instances. Is there a single batch file I can write that would set of multiple cmd instances and execute the set of DOS commands in each of the prompts?


回答1:


Your question seems to boil down to how to run a different series of commands in each instance of cmd.exe without having multiple command files.

There's a reasonably straightforward way of doing this. The idea is to run the same command file in each instance of cmd.exe, but pass it a command-line parameter that tells it which part of the job to do.

A useful trick here is to use the command-line parameter in a goto command, like this:

if not "%1" == "" goto :%1

start "Job 1" "%~dpfx0" job1
start "Job 2" "%~dpfx0" job2
goto :eof

:job1

echo Job 1
pause
exit

:job2

echo Job 2
pause
exit

Note also the use of %~dpfx0 to determine the full path and name of the current script. This has to be in quotes in case the path contains spaces, which means that (due to the odd syntax of the start command) you need to first explicitly specify a window title (also in quotes).




回答2:


How about something like:

start cmd /c dir c:\windows



来源:https://stackoverflow.com/questions/7612181/launching-multiple-shell-prompts-from-a-single-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!