[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 批处理命令start的几种用法有何区别?

我从网上下载了一段批处理代码,是用于windows xp的无人值守安装的,代码如下:
  1. REM +=======================================================+
  2. REM | Comment out what you don't need. These are mostly     |
  3. REM | examples to give you an idea of how it all works.     |
  4. REM +=======================================================+
  5. REM +=======================================================+
  6. REM | Finding CDROM driveletter                             |
  7. REM |-------------------------------------------------------|
  8. set tagfile=\WIN51
  9. for %%i in (c d e f g h i j k l m n o p q r s t u v w x y z) do if exist "%%i:%tagfile%" set CDDRIVE=%%i:
  10. REM +=======================================================+
  11. REM +=======================================================+
  12. REM | We should be already in system32, this is just to be  |
  13. REM | sure                                                  |
  14. REM |-------------------------------------------------------|
  15. %SystemDrive%
  16. cd %SystemRoot%\system32
  17. REM +=======================================================+
  18. REM +=======================================================+
  19. REM | Trick Windows into identifying the original setup.exe |
  20. REM | deleting the setup.exe will not work, just rename it  |
  21. REM |-------------------------------------------------------|
  22. if exist setup.exe ren setup.exe setupold.exe
  23. if exist setupORG.exe ren setupORG.exe setup.exe
  24. REM +=======================================================+
  25. %CDDRIVE%\Drivers\SetDevicePath.exe %CDDRIVE%\Drivers
  26. start %CDDRIVE%\Drivers\WatchDriverSigningPolicy.exe
  27. REM +=======================================================+
  28. REM | Finally start the installation with the originally    |
  29. REM | given parameters                                      |
  30. REM |-------------------------------------------------------|
  31. start /WAIT setup.exe %*
  32. REM +=======================================================+
复制代码
具体各行的用途,在代码中已经有所注释了,我现在有如下问题不明白,请高手帮助:
1、同样是调用外部程序,这个批处理中使用了三种方式:
(1)%CDDRIVE%\Drivers\SetDevicePath.exe %CDDRIVE%\Drivers
(2)start %CDDRIVE%\Drivers\WatchDriverSigningPolicy.exe
(3)start /WAIT setup.exe %*
其中,SetDevicePath.exe就是帮助将驱动程序所在路径添加进注册表的程序,运行的时候没有见到GUI;WatchDriverSigningPolicy.exe作用在于使Windows接受未签名的驱动程序,运行的时候也未见到GUI;setup.exe其实就是windows xp的GUI安装阶段的安装程序。
现在我的疑问是,这三种用法(即第一种,直接键入程序名;第二种,使用start;第三种,使用start /wait)有何区别。特别是第一种和第三种有何区别,我对批处理不是很熟,但我听说直接键入程序名的用法中批处理也需要等待该程序运行结束在继续执行后面的代码,那步就和start /wait一样了吗,为什么还需要特别使用start /wait。这个批处理的作者在同一个批处理中分别使用了上述三种用法,我相信应当是有区别的,但是我不明白,查了相关的资料和论坛的帖子也没有想明白。还请高手不吝赐教。
2、start /WAIT setup.exe %*一句中,后面的那个%*是什么意思,这个字符是start的参数还是批处理的其他用法的参数?

请问能把英文翻译过来一下不?学习
停下的理由千千万万,向前的理由一个就已足够!

TOP

  1. (1)%CDDRIVE%\Drivers\SetDevicePath.exe %CDDRIVE%\Drivers
  2.        直接在批处理中使用路径名而不使用任何命令和符号是可以直接执行该文件的,你可以试下,拖一个文件到cmd窗口并直接回车,批处理会自动执行该文件。但似乎有些特殊情况。
  3. (2)start %CDDRIVE%\Drivers\WatchDriverSigningPolicy.exe
  4.        start是打开文件的常用命令,这个没必要说了吧。
  5. (3)start /WAIT setup.exe %*
  6.        start/wait不过加多了一个参数/wait,wait是等待的意思,意思是执行某个文件或命令直到该文件执行结束后再继续下一步。
复制代码
寂寞是黑白的,但黑白不是寂寞,是永恒。BAT 需要的不是可能,而是智慧。

TOP

谢谢cjiabing版主的回复,可我还是不明白这几种用法之间的区别,特别是第一种 “直接在批处理中使用路径名”和第三种使用“start /wait”之间有什么区别,这两种用法不都是要等启动的程序运行结束后在继续执行后面的代码吗,那为什么要特别写上“start /wait”呢。

TOP

回复 4# evilwz


    多做几个试验就懂得了。
寂寞是黑白的,但黑白不是寂寞,是永恒。BAT 需要的不是可能,而是智慧。

TOP

回复 4# evilwz


    不加/wait是不会等待的

TOP

回复 1# evilwz

executableFilename

start /wait executableFilename
肯定是有区别的, 至少 cmd 历史版本会让 二者 有相当大的区别
即使 WinXP 32 位版, 至少你可以发现
直接在命令行下:
32bitGUIexecutableFilename
是不会等待 32bitGUIexecutableFilename 执行完才接受新的命令的


start /wait 32bitGUIexecutableFilename
无论在脚本中还是在命令行下都会等待 其执行完毕退出, 才会接受后面的命令或者执行后面的脚本

参考:
http://technet.microsoft.com/en-us/library/cc723564.aspx

If the command is a 16-bit or 32-bit Windows GUI executable program, the shell runs the program but does not wait for the command to complete.
If the command is a 32-bit console application, or a 16-bit MS-DOS application, the shell runs the command in the current console window and waits for the command to complete.

TOP

回复 1# evilwz

至于哪个版本的 command shell 对于 GUI 的等待问题, 最好实测检验(注意命令行下和脚本中可能会有不同的效果)

http://technet.microsoft.com/en-us/library/bb491005.aspx

TOP

%* 是参数的使用方式

参见:
http://www.microsoft.com/resourc ... rcent.mspx?mfr=true

Cmd.exe provides the batch parameter expansion variables %0 through %9. When you use batch parameters in a batch file, %0 is replaced by the batch file name, and %1 through %9 are replaced by the corresponding arguments that you type at the command line. To access arguments beyond %9, you need to use the shift command. For more information about the shift command, see Shift The %* batch parameter is a wildcard reference to all the arguments, not including %0, that are passed to the batch file.

The %* modifier is a unique modifier that represents all arguments passed in a batch file. You cannot use this modifier in combination with the %~ modifier. The %~ syntax must be terminated by a valid argument value.

TOP

但我听说直接键入程序名的用法中批处理也需要等待该程序运行结束在继续执行后面的代码,那步就和start /wait一样了吗?

这个我也是第一次听你说,不过测试结果确实“直接键入程序完全路径和start /wait 的效果是一样的”。

TOP

但我听说直接键入程序名的用法中批处理也需要等待该程序运行结束在继续执行后面的代码,那步就和start /wai ...
Hello123World 发表于 2012-4-13 19:09

Win7下确实是这样

TOP

返回列表