问题描述
我正在为 Windows 10 编写一个简单的 .bat 脚本;我有单个部分工作,但不是全部一起工作。 基本上我想要一个 .bat 文件:
-
从快捷方式启动 CMD shell,类似于
start "" "C:\Users............\System Tools\Command Prompt.lnk"
-
在那个 shell 中,转到我的 python 文件
"cd C:\Users...........\myPython\
的文件夹并执行py myFile.py %*
-
像第一步那样打开一个新的 CMD(可能将它放在远离 第一个这样它们就不会重叠)
-
将外壳背景颜色更改为自定义颜色(我可以使用
color NN
命令的默认颜色来实现) -
对 shell 2 重复步骤 2
解决方法
我不完全明白你想要做什么,但我认为你可以使用一些脚本来实现它:
例如你可以有 3 个这样的 bat 文件:
rem startboth.bat
start c:\path\to\my\folder\first.bat
start c:\path\to\my\folder\second.bat
rem first.bat
COLOR 4b
c:\Users\pnnp\Miniconda3\python.exe -v
rem second.bat
COLOR 4b
c:\Users\pnnp\Miniconda3\python.exe -m http.server
如果您点击 both.bat
,您将同时启动所需颜色的两个进程。
根据您的问题和随后的评论,这是我对您的批处理文件内容的最佳猜测:
@Start "Shell 1" /D "%UserProfile%\myPython" "%SystemRoot%\System32\cmd.exe" /D /K "py.exe myFile.py"
@Start "Shell 2" /D "%UserProfile%\myPython" "%SystemRoot%\System32\cmd.exe" /D /T:E5 /K "py.exe myFile.py"
我假设您应该能够根据 start
和 cmd
命令的使用信息自行调整标题、文件路径和颜色组合,即 start /?
和 cmd /?
)。