Win32 CMD批處理命令

1. win32批處理下,另開一個console執行進程X

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

//--------------------------------------------------------------------------------------
//example 1: 新開console,執行dir命令完畢後,不自動關閉console
start cmd /K dir 

//--------------------------------------------------------------------------------------
//example 2: 新開console,執行dir命令完畢後,自動關閉console
start cmd /C dir 

//--------------------------------------------------------------------------------------
//example 3: 完整示例
start /D D:\demo-dev\dev_native\demoICE\x64\Release cmd /K demoICE.exe server
start /D D:\demo-dev\dev_native\demoICE\x64\Release cmd /K demoICE.exe client

注意:start命令是不會擁塞當前控制檯的.bat執行的。python

2. 指定start的啓動目錄

使用start /D,示例以下:linux

start /D c:\

3. 與linux後臺運行(&)等價的start操做

使用start /b,示例以下:shell

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://blog.csdn.net/u012377333/article/details/41824787bash

4. 使用python腳本同時啓動多console進程

參考文獻:spa

  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

示例以下:.net

//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'], creationflags=CREATE_NEW_CONSOLE, 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, creationflags=CREATE_NEW_CONSOLE, cwd="D:\\demo-dev\\dev_native\\demoICE\\x64\\Release");
Popen(args_2, creationflags=CREATE_NEW_CONSOLE, cwd="D:\\demo-dev\\dev_native\\demoICE\\x64\\Release");
相關文章
相關標籤/搜索