Cha*_*adD 133 windows batch-file
如何使用WAIT选项的START命令
START /wait notepad.exe
START /wait notepad.exe
Run Code Online (Sandbox Code Playgroud)
...与使用CALL命令有什么不同?
CALL notepad.exe
CALL notepad.exe
Run Code Online (Sandbox Code Playgroud)
是否存在一种情况,其中一种可能表现不同,另一种情况取决于正在执行的内容?
jeb*_*jeb 162
对于exe文件,我认为差异几乎不重要.
但要启动一个exe,你甚至不需要CALL.
当启动另一个批处理时,它会有很大的不同,
因为CALL它将在同一个窗口中启动,并且被调用的批处理可以访问相同的变量上下文.
因此它也可以更改影响调用者的变量.
CALL将为被调用的批处理创建一个新的cmd.exe,如果没有/ b,它将打开一个新窗口.
由于它是一个新的上下文,因此无法共享变量.
附录:
使用START可以更改参数(对于批处理文件和exe文件),但仅限于包含插入符号或百分号的参数.
call myProg param1 param^^2 "param^3" %%path%%
Run Code Online (Sandbox Code Playgroud)
将扩展为(从批处理文件中)
myProg param1 param2 param^^3 <content of path>
Run Code Online (Sandbox Code Playgroud)
mck*_*ejm 15
我认为它们的表现应该基本相同,但也存在一些差异.
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.
Run Code Online (Sandbox Code Playgroud)
小智 9
在调用时call和start /wait调用之间存在一个有用的区别regsvr32.exe /s,例如,Gary在他的回答中提到了如何使用-a-get-the-application-exit-code-from-a-windows-command-line
call regsvr32.exe /s broken.dll
echo %errorlevel%
Run Code Online (Sandbox Code Playgroud)
将始终返回0但是
start /wait regsvr32.exe /s broken.dll
echo %errorlevel%
Run Code Online (Sandbox Code Playgroud)
将从regsvr32.exe返回错误级别
小智 6
这是我在并行运行批处理文件时发现的(同时使用不同的输入参数同时运行同一bat文件的多个实例):
假设您有一个执行长任务的exe文件,称为LongRunningTask.exe
如果直接从bat文件中调用exe,则只有对LongRunningTask的第一次调用会成功,而其余的将得到操作系统错误“进程已在使用文件”
如果使用此命令:
开始/ B / WAIT“”“ LongRunningTask.exe”“参数”
您将能够运行bat和exe的多个实例,同时仍然等待任务完成,然后bat继续执行其余命令。/ B选项是为了避免创建另一个窗口,为了使命令起作用,需要使用空引号,请参见下面的参考。
请注意,如果您一开始不使用/ WAIT,则LongRunningTask将与批处理文件中的其余命令同时执行,因此,如果其中一个命令需要LongRunningTask的输出,则可能会产生问题。
正在恢复:
这不能并行运行:
这将并行运行,并且只要命令的输出与bat文件的其余部分之间没有数据依赖性,就可以了:
这将并行运行并等待任务完成,因此您可以使用输出:
启动命令参考:如何从批处理文件运行程序,而在启动程序后不使控制台处于打开状态?
呼叫
在不停止父批处理程序的情况下从另一个调用一个批处理程序。call命令接受标签作为呼叫目标。在脚本或批处理文件之外使用时,调用在命令行无效。 https://technet.microsoft.com/zh-CN/library/bb490873.aspx
开始
启动一个单独的“命令提示符”窗口,以运行指定的程序或命令。如果不带参数使用,start将打开第二个命令提示符窗口。 https://technet.microsoft.com/zh-CN/library/bb491005.aspx
| 归档时间: |
|
| 查看次数: |
441638 次 |
| 最近记录: |