保留多个CMD窗口从批开放 [英] keep multiple cmd windows open from batch
问题描述
我怎样才能让一个批处理文件在自己的窗口中执行多个(Python)的脚本顺序,每一个,并保留所有这些窗口完成后打开?现在,我的批处理是一样的东西:
蟒蛇SCRIPT1
启动蟒蛇SCRIPT2
暂停/ CMD
但只有父窗口保持打开状态。
感谢。
环境:
视窗XP / Vista P>
[转]执行多个(Python)的脚本顺序,各自在自己的窗口,并保持所有打开的窗口完成后
块引用>#!的/ usr /斌/包膜蟒蛇
继续传递风格(CPS)的脚本。用法: $蟒蛇cps.py script1.py ARG1 ARG2 - script2.py A B C - script3.py ...
进口平台
进口SYS
从子导入调用如果len(sys.argv中)LT; 2:
sys.exit()#无关#定义启动新的终端命令
如果platform.system()==视窗:
new_window_command =CMD.EXE / C cmd.exe的启动/ C.split()
其他:#XXX这可以使更多的便携式
new_window_command =X-终端仿真器-e.split()#寻找到脚本ARGS结束
结束= sys.argv.index(' - '),如果 - 在sys.argv中其他LEN(sys.argv中)#调用脚本;等待它结束;忽略错误
致电([sys.executable] + sys.argv中[1:结束])#启动新的窗口;自称;通过休息;忽略错误
其余= sys.argv中[结束+ 1:]
如果休息:
致电(new_window_command + sys.executable,sys.argv中[0] +休息)打印(preSS Enter退出)#NOTE:避免的raw_input /输入py3k有心计
sys.stdin.readline()它支持他们的论据尽可能多的脚本,你可以在命令行上提供。
如果您不使用脚本的参数;你可以简化用法:
$蟒蛇cps.py script1.py script2.py script3.py
注:没有
-
脚本之间。您需要修改code在这种情况下:
- 设置
结束= 2
- 和
=休息sys.argv中[结束:]
(注:没有+1
)How can I make a batch file execute multiple (Python) scripts sequentially, each in their own window, and keep all those windows open upon completion? Right now, my batch is something like:
python script1 start python script2 pause/cmd
But only the parent window stays open.
thanks.
Environment: Windows XP/Vista
解决方案[to] execute multiple (Python) scripts sequentially, each in their own window, and keep all those windows open upon completion
#!/usr/bin/env python """Continuation-passing style (CPS) script. Usage: $ python cps.py script1.py arg1 arg2 -- script2.py a b c -- script3.py ... """ import platform import sys from subprocess import call if len(sys.argv) < 2: sys.exit() # nothing to do # define a command that starts new terminal if platform.system() == "Windows": new_window_command = "cmd.exe /c start cmd.exe /c".split() else: #XXX this can be made more portable new_window_command = "x-terminal-emulator -e".split() # find where script args end end = sys.argv.index('--') if '--' in sys.argv else len(sys.argv) # call script; wait while it ends; ignore errors call([sys.executable] + sys.argv[1:end]) # start new window; call itself; pass the rest; ignore errors rest = sys.argv[end+1:] if rest: call(new_window_command + [sys.executable, sys.argv[0]] + rest) print("Press Enter to exit") #NOTE: to avoid raw_input/input py3k shenanigans sys.stdin.readline()
It supports as many scripts with their arguments as you can supply on the command line.
If you don't use arguments for scripts; you could simplify the usage:
$ python cps.py script1.py script2.py script3.py
Note: no
--
between scripts. You need to modify the code in this case:
- set
end = 2
- and
rest = sys.argv[end:]
(Note: no+1
)这篇关于保留多个CMD窗口从批开放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!