bat多任务并行处理
来源:互联网 发布:雅思写作批改知乎 编辑:程序博客网 时间:2024/05/16 04:36
如何同时运行多个程序?
-- by benbenknight
同时运行多个程序一般有两种方式,一种是串行的,即运行完一个程序再运行下一个;一种是并行的,即程序运行后不必等待执行结束就运行下一个。
最简单的方法就是使用批处理文件或Windows脚本,也可以使用VC写个小程序,读取配置文件中的程序路径及参数,循环调用CreateProcess函数即可。下面主要介绍前两种方法。
一、批处理文件
批处理命令中,call和直接输入程序路径采用等待程序结束方式,start采用的是不等待的方式。下面几个小例子中,其中RunS1.bat、RunS2.bat为串行运行,RunP.bat为并行运行。
---------------------------------
文件RunS1.bat:
echo off
rem RunS1.bat
rem 同时串行运行多个程序
set cmd1=D:test1
set cmd2=D:test2
call %cmd1%
call %cmd2%
---------------------------------
文件RunS2.bat:
echo off
rem RunS2.bat
rem 同时串行运行多个程序
set cmd1=D:test1
set cmd2=D:test2
%cmd1%
%cmd2%
---------------------------------
文件RunP.bat:
echo off
rem RunP.bat
rem 同时并行运行多个程序
set cmd1=D:test1
set cmd2=D:test2
start %cmd1%
start %cmd2%
---------------------------------
二、Windows脚本
WshShell对象的Run方法即可采用等待程序结束的方式,也可采用不等待的方式;Exec方法采用不等待的方式。下面几个小例子中,
---------------------------------
文件RunS.vbs:
' RunS.vbs
' 同时串行运行多个程序
strCmd1 = "D:\test1.exe"
strCmd2 = "D:\test2.exe"
Set wshShell = CreateObject("WScript.Shell")
nWindowStyle = 1 ' 激活并显示窗口
bWaitOnReturn = 1 ' 等待程序执行完毕再执行下一条语句
wshShell.Run strCmd1,nWindowStyle,bWaitOnReturn
wshShell.Run strCmd2,nWindowStyle,bWaitOnReturn
---------------------------------
文件RunP1.vbs:
' RunP1.vbs
' 同时并行运行多个程序
strCmd1 = "D:\test1.exe"
strCmd2 = "D:\test2.exe"
Set wshShell = CreateObject("WScript.Shell")
nWindowStyle = 1 ' 激活并显示窗口
bWaitOnReturn = 0 ' 不必等待程序执行完毕再执行下一条语句
wshShell.Run strCmd1,nWindowStyle,bWaitOnReturn
wshShell.Run strCmd2,nWindowStyle,bWaitOnReturn
---------------------------------
文件RunP2.vbs:
' RunP2.vbs
' 同时并行运行多个程序
strCmd1 = "D:\test1.exe"
strCmd2 = "D:\test2.exe"
Set wshShell = CreateObject("WScript.Shell")
wshShell.Exec(strCmd1)
wshShell.Exec(strCmd2)
---------------------------------
等待并行程序结束:
:loop
ping -n 2 127.1>nul
tasklist /fi "windowtitle eq 并行*" |findstr "cmd.exe">nul&&(goto loop)
- bat多任务并行处理
- bat多任务并行处理
- DOS-BAT并行处理
- SAS多任务并行处理,利用systask
- PHP5实现多任务并行处理
- mono touch并行多任务处理
- bat处理解决运行多个任务时的任务
- PHP多进程处理并行处理任务实例
- PHP多进程处理并行处理任务实例
- PHP多进程处理并行处理任务实例
- oozie fork多mapreduce任务并行处理示例
- PHP使用QPM实现多进程并行任务处理程序
- PHP 使用 QPM 实现多进程并行任务处理程序
- 创建ExecutorService并行处理任务,导致内存不足
- Spring定时任务并行(异步)处理
- 第二十一节:多任务并行处理两路跑马灯
- shell&bat并行执
- 基于Hadoop实现通用的并行任务处理
- iPhone iPad 开发电子书打包下载
- Oracle数据库的启动和关闭方式小结
- Oracle归档模式的命令及参数说明
- 超声波传感器 URM04 V2.0 的使用
- JAVA - "Add default serial version ID" et "Add generated serail version ID"
- bat多任务并行处理
- eclipse-for-j2ee-3.4.0(包含)以上版本开发大项目性能优化
- 【二维树状数组】POJ 1195
- 一位软件工程师6年的总结
- 黑马程序员——数组操作
- 解决mysql忘记密码
- C++ primer读书笔记
- 上传应用程序到App Store出现图标报错问题的解决办法
- 学会发现