python多控制台窗口_python-批量打开多个控制台窗口

如何使批处理文件在各自的窗口中依次执行多个(Python)脚本,并在完成后使所有这些窗口保持打开状态?现在,我的批处理是这样的:

python script1

start python script2

pause/cmd

但是只有父窗口保持打开状态.

谢谢.

环境:

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()

它可以在命令行中提供尽可能多的脚本及其参数.

如果您不对脚本使用参数;您可以简化用法:

$python cps.py script1.py script2.py script3.py

注意:否-脚本之间.在这种情况下,您需要修改代码:

>设定结束= 2

>和rest = sys.argv [end:](注意:否1)

标签:cmd,windows,python,batch-file

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值