从批处理(.bat)文件运行几个cmd命令

时间:2023-02-10 02:31:37

Scenario: I'm developing a project in Python and Django. Every time I need to activate my virtual environment and then run webserver. What I do is as follows..

场景:我正在用Python和Django开发一个项目。每次我需要激活我的虚拟环境然后运行webserver。我的工作如下..

run cmd then enter the following command

运行cmd然后输入以下命令

C:\Users\azad>e:

E:>cd E:\Development\Python\djangogirls

E:\Development\Python\djangogirls>dgvenv\Scripts\activate

this command activate my virtual environment and change my working directory(command prompts)

此命令激活我的虚拟环境并更改我的工作目录(命令提示符)

(dgvenv) E:\Development\Python\djangogirls>python manage.py runserver

(dgvenv)E:\ Development \ Python \ djangogirls> python manage.py runserver

Now I want to create a windows batch(.bat) file so that I can do the above task with one click.

现在我想创建一个Windows批处理(.bat)文件,以便我可以一键完成上述任务。

If I could not make a sense please reply me.

如果我无法理解,请回复我。

2 个解决方案

#1


0  

You could try this:

你可以试试这个:

@CD /D "E:\Development\Python\djangogirls"
@Call "dgvenv\Scripts\activate.bat"
@python manage.py runserver

#2


0  

Create a .bat file with your text editor. Then type in the commands you need. See below code as an example:

使用文本编辑器创建.bat文件。然后输入您需要的命令。以下面的代码为例:

@echo off
cd C:\Users\azad
cd E:\Development\Python\djangogirls
dgvenv\Scripts\activate
@py.exe
python manage.py runserver

#1


0  

You could try this:

你可以试试这个:

@CD /D "E:\Development\Python\djangogirls"
@Call "dgvenv\Scripts\activate.bat"
@python manage.py runserver

#2


0  

Create a .bat file with your text editor. Then type in the commands you need. See below code as an example:

使用文本编辑器创建.bat文件。然后输入您需要的命令。以下面的代码为例:

@echo off
cd C:\Users\azad
cd E:\Development\Python\djangogirls
dgvenv\Scripts\activate
@py.exe
python manage.py runserver