加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

Win32 CMD批处理命令

发布时间:2020-12-14 02:10:46 所属栏目:Windows 来源:网络整理
导读:1. win32批处理下,另开一个console执行进程X 使用start [/K|/C],示例: //--------------------------------------------------------------------------------------//example 1: 新开console,执行dir命令完毕后,不自动关闭consolestart cmd /K dir //-

1. win32批处理下,另开一个console执行进程X

使用start [/K|/C],示例:

//--------------------------------------------------------------------------------------
//example 1: 新开console,执行dir命令完毕后,不自动关闭console
start cmd /K dir 

//--------------------------------------------------------------------------------------
//example 2: 新开console,执行dir命令完毕后,自动关闭console
start cmd /C dir 

//--------------------------------------------------------------------------------------
//example 3: 完整示例
start /D D:demo-devdev_nativedemoICEx64Release cmd /K demoICE.exe server
start /D D:demo-devdev_nativedemoICEx64Release cmd /K demoICE.exe client

注意:start命令是不会拥塞当前控制台的.bat执行的。

2. 指定start的启动目录

使用start /D,示例如下:

start /D c:

3. 与linux后台运行(&)等价的start操作

使用start /b,示例如下:

in win32 console:
start /b iperf.exe > c:iperf_multicast_server_logfile.txt

in linux console:
/root/iperf1.7 > /root/iperf_multicast_client_logfile.txt &

参考文献:http://www.voidcn.com/article/p-atmsokii-qn.html

4. 使用python脚本同时启动多console进程

参考文献:

  1. https://stackoverflow.com/questions/6469655/how-can-i-spawn-new-shells-to-run-python-scripts-from-a-base-python-script
  2. https://stackoverflow.com/questions/15899798/subprocess-popen-in-different-console
  3. https://docs.python.org/2/library/subprocess.html

示例如下:

//example 1:
from subprocess import Popen,CREATE_NEW_CONSOLE
Popen('cmd',creationflags=CREATE_NEW_CONSOLE)

//--------------------------------------------------------------------------------------
//example 2:
from sys import executable
from subprocess import Popen,CREATE_NEW_CONSOLE
Popen([executable,'script.py'],creationflags=CREATE_NEW_CONSOLE)

//--------------------------------------------------------------------------------------
//example 3:
from subprocess import Popen,CREATE_NEW_CONSOLE
Popen('cmd dir',creationflags=CREATE_NEW_CONSOLE,cwd='c:')
Popen(['cmd','/C','dir'],cwd='c:')

//--------------------------------------------------------------------------------------
//example 4:
from shlex import split
from subprocess import Popen,CREATE_NEW_CONSOLE
cmd_1 = "cmd /K demoICE.exe server";
cmd_2 = "cmd /K demoICE.exe client";
args_1 = split(cmd_1);
args_2 = split(cmd_2);
Popen(args_1,cwd="D:demo-devdev_nativedemoICEx64Release");
Popen(args_2,cwd="D:demo-devdev_nativedemoICEx64Release");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读