作者uranusjr (←这人是超级笨蛋)
看板Python
标题Re: [问题]如何让os.system执行多笔指令
时间Thu Nov 27 18:50:36 2014
※ 引述《arnold0613 (凯)》之铭言:
: http://djangogirlstaipei.gitbooks.io/django-girls-taipei-tutorial/content/
: 建议venv下执行 所以每次练习时候都必须执行
: VENV/bin/activate
: python manage.py runserver
: 我想到os.system 可以执行指令,但是只有执行一次就关闭视窗
: 不知道该如何做到这需求
所以你是懒得写两行, 只想写一行?
说真的这写 bash 或 batch script 比较快
Windows:
把下面两行存成 run.bat
VENV\Scripts\activate
python manage.py runserver
其他 (假设你用 bash):
1. 把下面三行存成 run (没有副档名)
#!/bin/bash
. VENV/bin/activate
python manage.py runserver
2. 在 command line 用以下指令把 run 档变成可执行档
chmod +x run
然後你之後就 cd 进去执行 ./run 就可以一次跑两个指令了
不过说真的不是很建议这样做
当然你最常执行的指令是 runserver
但在开发时你还是会需要执行一些其他指令
在执行这些指令时还是会需要 activate venv
长久看来直接分两步还比较方便一些
这样你要执行其他指令时只要停止 runserver 就可以执行
--
Les grandes et les meilleurs
tone from "Zadok the Priest"
Eine grosse stattliche Veranstaltung
by F. Handel
THE MAIN EVENT! These are the men
Sie sind die Besten
"Champions League" by Tony Britten THESE ARE THE CHAMPIONS!
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.94.57
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/Python/M.1417085438.A.E47.html
※ 编辑: uranusjr (60.251.42.102), 11/27/2014 19:38:45