如何控制批处理文件的时间 [英] How to control the timing of a batch file

查看:81
本文介绍了如何控制批处理文件的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我正在尝试建立一个批处理文件,其中我想一次打开更多的8个应用程序.
所以我写了这个

Hi all

I am trying to build a batch file in which i want to open more 8 application at a time.
so i wrote this

echo off
cls
start /d "" firefox.exe http://www.ourgoalplan.com
start /d "" chrome.exe http://www.gmail.com
start /d "" iexplore.exe http://www.yahoo.com
start /d "" wlmail.exe
start /d "C:\Program Files\GNU\WinCvs 2.0" wincvs.exe
start /d "C:\Program Files\MySQL\MySQL Workbench 5.2 CE" MySQLWorkbench.exe
start /d "" VCSExpress.exe
start /d "" VWDExpress.exe


它可以正常工作,但需要花费更多时间,因为一次运行8个应用程序.
所以我想在第一个应用程序结束后运行第二个应用程序,第三个应用程序在第二个应用程序结束后执行.

如何满足以上要求?
或给我一些建议....

请帮助

提前谢谢.


Its working fine but it takes more time because at a time 8 applications runs.
So i want to run the second application after the first application ends and the third one will execute after the second application end.

How to do the above requirement?
or Give me some suggestions ....

Please Help

Thanks In advance.

推荐答案

start /d "" firefox.exe http://www.ourgoalplan.com /wait


在命令行中键入start /?将为您提供所有命令选项.


Typing start /? at the command line will give you all the command options.


除了Richard的完美答案:

自DOS时代以来,批处理功能已得到了很大的改进,但是对于许多人来说,这一事实仍然不明显.即使批处理语言过于基本并且不足以处理许多复杂的任务,但是许多创新使它对于解决范围很广的简单即席问题是可以接受的.现在甚至可以使用带有参数的子程序及其带有正确返回给调用者(而不是跳转)的调用.这是一个有趣的批处理文件,有助于生成有关当前帮助的文档.您可以将其用于所有批次需求:

In addition to the perfect answer by Richard:

The batch functionality has been considerably improved since DOS time, but for many people this fact remained unnoticeable. Even though batch language is too rudimentary and inadequate to many more or less complicated tasks, many innovations makes it acceptable for a solving of a pretty wide range of simple ad-hoc problem. Even subprograms with parameters and their calls with proper returns to the caller (not jumps) are now available. Here is one interesting batch file which helps to generate documentation on current-day help. You can use it for all your batch needs:

@ECHO OFF
IF "%OS%"=="Windows_NT" SETLOCAL DISABLEDELAYEDEXPANSION

:: Version number for this batch file
SET MyVer=1.40

:: Display "about"
ECHO.
ECHO AllHelp.bat,  Version %MyVer% for Windows NT 4 / 2000 / XP
ECHO Generate an HTML help file for "all" available commands
ECHO.
ECHO Note:
ECHO This batch file uses the redirected output of the HELP command to generate the
ECHO HTML file. Because some commands use "special" characters like ^&, ^<, and ^> in
ECHO their help screen, not all output is displayed correctly in the browser.
ECHO Known issues: skipped ^<space^> "tag" in CMD's special character list and skipped
ECHO \^<xyz and xyz\^> word position references in FINDSTR's output.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO.
ECHO Improved white space handling by Johan Parlevliet
ECHO Further improvements for NT 4 by Ulf Lindb„ck
ECHO.
ECHO.
ECHO.

IF NOT "%OS%"=="Windows_NT" SET MyVer=
IF NOT "%OS%"=="Windows_NT" GOTO End

:: Store current code page and then set code page for European languages
FOR /F "tokens=*" %%A IN ('CHCP') DO FOR %%B IN (%%A) DO SET CHCP=%%B
CHCP 1252 >NUL 2>&1

:: Start writing HTML file
ECHO Writing HTML header . . .
> allhelp.htm ECHO ^<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"^>
>>allhelp.htm ECHO ^<HTML^>
>>allhelp.htm ECHO ^<HEAD^>
:: Read Windows version using VER command
FOR /F "tokens=1 delims=[" %%A IN ('VER') DO SET Ver=%%A
FOR /F "tokens=1* delims= " %%A IN ('ECHO.%Ver%') DO SET Ver=%%B
:: Read latest Service Pack from registry
CALL :GetSP
>>allhelp.htm ECHO ^<TITLE^>Help for all %Ver%%SP% commands^</TITLE^>
>>allhelp.htm ECHO ^<META NAME="generator" CONTENT="AllHelp.bat, Version %MyVer%, by Rob van der Woude"^>
>>allhelp.htm ECHO ^</HEAD^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<BODY^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A NAME="Top"^>^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<CENTER^>
>>allhelp.htm ECHO ^<H1^>%Ver%%SP% commands^</H1^>
FOR /F "tokens=* delims=" %%A IN ('VER') DO SET Ver=%%A
>>allhelp.htm ECHO ^<H3^>%Ver%^</H3^>
>>allhelp.htm ECHO ^</CENTER^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
>>allhelp.htm ECHO.

ECHO Creating command index table . . .
SET FirstCell=1
>>allhelp.htm ECHO ^<TABLE BORDER="0"^>
:: Skip 1 or 2 lines of HELP command's header
FOR /F "tokens=1 delims=[]" %%A IN ('HELP ^| FIND /N "."') DO IF %%A LEQ 2 SET Skip=+%%A
:: MORE's /T switch translates tabs to a fixed number of spaces; tip by Johan Parlevliet
:: In NT 4, MORE's /E switch may be necessary; tip by Ulf Lindb„ck
:: %Skip% skips 1 or 2 lines of HELP command's header
FOR /F "tokens=* delims=" %%A IN ('HELP ^| MORE /E %Skip% /T8') DO CALL :DispLine "%%A"
>>allhelp.htm ECHO ^</TD^>^</TR^>
>>allhelp.htm ECHO ^</TABLE^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
>>allhelp.htm ECHO.

ECHO Writing help for each command:
:: MORE's /T switch translates tabs to a fixed number of spaces; tip by Johan Parlevliet
:: In NT 4, MORE's /E switch may be necessary; tip by Ulf Lindb„ck
FOR /F "tokens=* delims=" %%A IN ('HELP ^| MORE /E %Skip% /T8') DO CALL :DispFull "%%A"

ECHO Closing HTML file
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<DIV ALIGN="Center"^>
>>allhelp.htm ECHO ^<P^>This HTML file was generated by:^<BR^>
>>allhelp.htm ECHO ^<B^>AllHelp.bat^</B^>, Version %MyVer%
>>allhelp.htm ECHO for Windows NT^&nbsp;4^&nbsp;/^&nbsp;2000^&nbsp;/^&nbsp;XP^<BR^>
>>allhelp.htm ECHO Written by Rob van der Woude^<BR^>
>>allhelp.htm ECHO ^<A HREF="http://www.robvanderwoude.com"^>http://www.robvanderwoude.com^</A^>^</P^>
>>allhelp.htm ECHO ^</DIV^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^</BODY^>
>>allhelp.htm ECHO ^</HTML^>

ECHO.
ECHO An HTML help file "allhelp.htm" has been created and stored in the current
ECHO directory.
ECHO.
ECHO Now starting display of "allhelp.htm" . . .
START "AllHelp" allhelp.htm

:: End of main batch program
CHCP %CHCP% >NUL 2>&1
ENDLOCAL
GOTO:EOF


:: Subroutines


:DispLine
SET Line=%1
SET Line=%Line:(=^(%
SET Line=%Line:)=^)%
SET Line=%Line:"=%
SET Command=%Line:~0,8%
SET Command=%Command: =%
IF DEFINED Command CALL :DispCmdLine %Command%
FOR /F "tokens=1* delims= " %%a IN ('ECHO.%*') DO SET Descr=%%b
SET Descr=%Descr:"=%
>>allhelp.htm ECHO.%Descr%
GOTO:EOF


:DispCmdLine
IF "%FirstCell%"=="0" IF DEFINED Command (>>allhelp.htm ECHO ^</TD^>^</TR^>)
SET Command=%1
IF DEFINED Command (>>allhelp.htm ECHO ^<TR^>^<TH ALIGN="left" VALIGN="top"^>^<A HREF="#%Command%"^>%Command%^</A^>^</TH^>^<TD^>^&nbsp;^&nbsp;^&nbsp;^</TD^>^<TD^>)
SET FirstCell=0
SET Command=
GOTO:EOF


:DispFull
SET Line=%1
SET Command=%Line:~1,8%
SET Command=%Command: =%
IF DEFINED Command CALL :WriteFull %Command%
SET Command=
GOTO:EOF


:GetSP
SET SP=
:: Export registry tree to temporary file
START /WAIT REGEDIT.EXE /E "%Temp%.\%~n0.dat" "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
IF NOT EXIST "%Temp%.\%~n0.dat" GOTO:EOF
:: Read value of "CSDVersion" from temporary file
FOR /F "tokens=2 delims==" %%A IN ('TYPE "%Temp%.\%~n0.dat" ^| FIND /I "CSDVersion"') DO SET SP=%%~A
:: Check if value is valid
ECHO.%SP% | FIND /I "Service Pack" >NUL
IF ERRORLEVEL 1 SET SP=
DEL "%Temp%.\%~n0.dat"
:: Use a shorter notation
IF DEFINED SP SET SP=%SP:Service Pack=SP%
GOTO:EOF


:WriteFull
ECHO.  %1 . . .
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A NAME="%~1"^>^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<H2^>%1^</H2^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<PRE^>
>>allhelp.htm HELP %1
>>allhelp.htm ECHO ^</PRE^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<A HREF="#Top"^>Back to the top of this page^</A^>
>>allhelp.htm ECHO.
>>allhelp.htm ECHO ^<P^>^&nbsp;^</P^>
>>allhelp.htm ECHO.
GOTO:EOF

:End



非常抱歉,我不记得该脚本的来源,但是该脚本的作者Rob van der Woude和撰稿人Johan Parlevliet是用代码编写的,非常感谢他们提供的这个有用的实用程序.

—SA



I''m really sorry that I cannot remember the source of this script, but its author Rob van der Woude and contributor Johan Parlevliet are written in the code, great thanks to them for this useful utility.

—SA


您有几个选择,但是没有一个会是您想要的.我不知道一种监视过程以查看其是否完成的方法.但是,您可以在每个项目之间放置一个"PAUSE"(暂停),这将等待用户按任意键以使批次继续.那可能不理想.

其他解决方案涉及一些黑客行为.基本上,您执行的网络命令所花费的时间是已知的(ping,netsh等),这些时间可用作延迟.最好是ping,因为您可以确定延迟多长时间.

这是一篇有关如何执行此操作的更多信息的文章:
http://www.robvanderwoude.com/wait.php [
You have a couple of options but none of them are going to be exactly what you would like. I don''t know of a way to monitor a process to see that it has completed. However, you can put a "PAUSE" between each item, which will wait for the user to press any key for the batch to continue. That probably isn''t ideal.

The other solutions involve a bit of hackery. Basically you do a network command that takes a known amount of time (ping, netsh, etc.) These can be used as delays. Probably the best is the ping, since you can determine how long to make the delay.

Here is an article with more information on how to do this:
http://www.robvanderwoude.com/wait.php[^]


这篇关于如何控制批处理文件的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆