CALL命令与启动/ WAIT选项

具有WAIT选项的START命令如何?

START /wait notepad.exe START /wait notepad.exe 

…与使用CALL命令有什么不同?

 CALL notepad.exe CALL notepad.exe 

有没有这样一种情况,一个人可能会有不同的performance,另一个则依赖于正在执行的事情?

对于exe文件,我想这些差异几乎是不重要的。
但要启动一个exe,你甚至不需要调用。

当开始另一批时,这是一个很大的区别,
因为CALL将在同一个窗口中启动它,被调用的批次可以访问相同的variables上下文。
所以它也可以改变影响调用者的variables。

START将为被调用的批处理创build一个新的cmd.exe,不用/ b它将打开一个新的窗口。
由于这是一个新的上下文,variables不能共享。

附录:
使用CALL可以更改参数(批处理和exe文件),但只有当它们包含插入符号或百分号时。

 call myProg param1 param^^2 "param^3" %%path%% 

将被扩展到(从一个batch file中)

 myProg param1 param2 param^^3 <content of path> 

我认为他们应该performance一般,但也有一些差异。 START通常用于启动应用程序或启动给定文件types的默认应用程序。 这样,如果你START http://mywebsite.com它不会做START iexplore.exe http://mywebsite.com

START myworddoc.docx将启动Microsoft Word并打开myworddoc.docx。 CALL myworddoc.docx做同样的事情…但是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时,在callstart /wait之间有一个有用的区别,同样在Gary的回答中也引用了他的回答, 窗口的命令行

 call regsvr32.exe /s broken.dll echo %errorlevel% 

将始终返回0,但

 start /wait regsvr32.exe /s broken.dll echo %errorlevel% 

将从regsvr32.exe中返回错误级别

呼叫

从另一个调用一个批处理程序而不停止父批处理程序。 呼叫命令接受标签作为呼叫的目标。 在脚本或batch file之外使用时,调用在命令行上不起作用。 https://technet.microsoft.com/en-us/library/bb490873.aspx

开始

启动单独的“命令提示符”窗口以运行指定的程序或命令。 没有参数使用,开始打开第二个命令提示符窗口。 https://technet.microsoft.com/en-us/library/bb491005.aspx

这是我在并行运行batch file时find的(同一个bat文件在不同input参数下同时运行的多个实例):

比方说,你有一个执行称为LongRunningTask.exe长任务的exe文件

如果您直接从bat文件中调用exe文件,只有第一次调用LongRunningTask才会成功,而其余的将会得到一个操作系统错误“文件已被进程使用”

如果你使用这个命令:

启动/ B / WAIT“”“LongRunningTask.exe”“参数”

您将能够运行bat和exe的多个实例,同时仍在等待任务完成,然后bat继续执行剩余的命令。 / B选项是为了避免创build另一个窗口,需要使用空引号才能使命令正常工作,请参阅下面的参考资料。

请注意,如果您在开始时不使用/ WAIT,则LongRunningTask将与batch file中的其余命令同时执行,因此,如果其中一个命令需要输出LongRunningTask,则可能会产生问题

恢复:

这不能并行运行:

  • 调用LongRunningTask.exe

这将并行运行,只要命令的输出和bat文件的其余部分之间没有数据依赖关系即可:

  • 启动/ B“”“LongRunningTask.exe”“参数”

这将并行运行并等待任务完成,以便您可以使用输出:

  • 启动/ B / WAIT“”“LongRunningTask.exe”“参数”

启动命令参考: 程序启动后,如何从batch file运行程序而不打开控制台?