简体   繁体   English

如何编写脚本以从快捷方式运行 2 个 CMD 实例和(Win 10)内的 2 个 python 程序?

[英]How to write a script to run 2 instances of CMD from shortcut and 2 python programs within (Win 10)?

I'm writing a simple.bat script for Windows 10;我正在为 Windows 10 编写一个 simple.bat 脚本; I have the single parts working but not all together.我有单个部分工作,但不是全部一起工作。 Basically I want a.bat file that:基本上我想要一个 .bat 文件:

  1. launches a CMD shell from the shortcut, something like start "" "C:\Users............\System Tools\Command Prompt.lnk"从快捷方式启动 CMD shell,例如start "" "C:\Users............\System Tools\Command Prompt.lnk"

  2. in that shell, go to the folder of my python file "cd C:\Users...........\myPython\ and executes py myFile.py %* in that shell, go to the folder of my python file "cd C:\Users...........\myPython\ and py myFile.py %*

  3. Open a new CMD like at step one (possibly position it away from the first one so they don't overlap)像第一步一样打开一个新的 CMD (可能 position 它远离第一个,所以它们不会重叠)

  4. Change shell background color to custom color (I can do it with the default colors of color NN command)将 shell 背景颜色更改为自定义颜色(我可以使用color NN命令的默认 colors 来完成)

  5. Repeat step 2 for shell 2对 shell 2 重复步骤 2

I don't completely get what you want to do but you I think you can achieve it using some scripts:我没有完全得到你想要做的事情,但你我认为你可以使用一些脚本来实现它:

For example you can have 3 bat files like that:例如,您可以拥有 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

Than if you click on both.bat you will launch both processes in parallel with the wanted color.如果您单击both.bat ,您将同时启动两个进程并使用所需的颜色。

From your question, and subsequent comments, this is my best guess for your batch file content:根据您的问题和随后的评论,这是我对您的批处理文件内容的最佳猜测:

@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"

I'll assume that you should be able to adjust the titles, file paths, and color combination, yourself, based upon the usage information for the start and cmd commands, (ie start /? , and cmd /? ).我假设您应该能够根据startcmd命令(即start /?cmd /? )的使用信息自行调整标题、文件路径和颜色组合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM