如何使用带有WAIT选项的START命令
START /wait notepad.exe
START /wait notepad.exe
...使用RETURN命令有什么不同于使用CALL命令吗?
CALL notepad.exe
CALL notepad.exe
执行的任务不同,是否存在一个情况,一个人的行为可能会与另一个人不同?
如何使用带有WAIT选项的START命令
START /wait notepad.exe
START /wait notepad.exe
...使用RETURN命令有什么不同于使用CALL命令吗?
CALL notepad.exe
CALL notepad.exe
执行的任务不同,是否存在一个情况,一个人的行为可能会与另一个人不同?
对于exe文件,我认为差异几乎不重要。
但是要启动exe甚至不需要CALL
。
当启动另一个批处理文件时,这是一个很大的区别,
因为CALL
会在同一个窗口中启动它,并且被调用的批处理文件可以访问相同的变量上下文。
因此,它也可以更改影响调用者的变量。
START
将为被调用的批处理文件创建一个新的cmd.exe,并且在没有/b的情况下,它将打开一个新窗口。
由于这是一个新的上下文,变量无法共享。
使用start /wait <prog>
- 当<prog>
结束时,环境变量的更改会丢失
- 调用者会等待,直到<prog>
完成
使用call <prog>
- 对于exe文件,它可以省略,因为它等同于只启动<prog>
- 对于一个exe-prog,调用者批处理文件会等待或异步启动exe,但其行为取决于exe本身。
- 对于batch文件,当被调用的<batch-file>
完成时,调用者批处理文件将继续执行,WITHOUT call不会将控制返回给调用者批处理文件
使用CALL
可以更改参数(对于批处理和exe文件),但只有当它们包含插入符或百分号时。
call myProg param1 param^^2 "param^3" %%path%%
将会被扩展为(在批处理文件内部)
myProg param1 param2 param^^3 <content of path>
start /wait /b cmd /c <batchfile.bat>
,因为批处理文件会在同一个命令窗口中依次运行。 - linux64kbcall batchfile.bat
。 - jeb我认为它们应该表现得大致相同,但还是有一些区别。START
通常用于启动应用程序或启动给定文件类型的默认应用程序。这样,如果你输入START http://mywebsite.com
,它就不会执行START iexplore.exe http://mywebsite.com
。
START myworddoc.docx
将启动Microsoft Word并打开myworddoc.docx。 CALL myworddoc.docx
也能实现同样的功能……但是START
提供了更多的选项来设置窗口状态和其他属性。它还允许设置进程优先级和亲和性。
简而言之,由于START
提供了额外的选项,因此应该选择它作为您的工具。
START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
[/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
[command/program] [parameters]
"title" Title to display in window title bar.
path Starting directory.
B Start application without creating a new window. The
application has ^C handling ignored. Unless the application
enables ^C processing, ^Break is the only way to interrupt
the application.
I The new environment will be the original environment passed
to the cmd.exe and not the current environment.
MIN Start window minimized.
MAX Start window maximized.
SEPARATE Start 16-bit Windows program in separate memory space.
SHARED Start 16-bit Windows program in shared memory space.
LOW Start application in the IDLE priority class.
NORMAL Start application in the NORMAL priority class.
HIGH Start application in the HIGH priority class.
REALTIME Start application in the REALTIME priority class.
ABOVENORMAL Start application in the ABOVENORMAL priority class.
BELOWNORMAL Start application in the BELOWNORMAL priority class.
NODE Specifies the preferred Non-Uniform Memory Architecture (NUMA)
node as a decimal integer.
AFFINITY Specifies the processor affinity mask as a hexadecimal number.
The process is restricted to running on these processors.
The affinity mask is interpreted differently when /AFFINITY and
/NODE are combined. Specify the affinity mask as if the NUMA
node's processor mask is right shifted to begin at bit zero.
The process is restricted to running on those processors in
common between the specified affinity mask and the NUMA node.
If no processors are in common, the process is restricted to
running on the specified NUMA node.
WAIT Start application and wait for it to terminate.
当调用regsvr32.exe /s
时,call
和start /wait
之间存在一个有用的区别,这也是由Gary在他回答的how-do-i-get-the-application-exit-code-from-a-windows-command-line中提到的。
call regsvr32.exe /s broken.dll
echo %errorlevel%
将始终返回0,但是
start /wait regsvr32.exe /s broken.dll
echo %errorlevel%
将返回regsvr32.exe的错误级别。
Call
调用另一个批处理程序而不停止父批处理程序。 Call命令接受标签作为调用目标。当在脚本或批处理文件之外使用时,Call命令在命令行上没有任何影响。 https://technet.microsoft.com/en-us/library/bb490873.aspx
Start
启动一个独立的命令提示符窗口以运行指定的程序或命令。如果没有参数使用,start会打开第二个命令提示符窗口。 https://technet.microsoft.com/en-us/library/bb491005.aspx