中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 14:46
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » Please tell me the difference between call and start when calling files?
Printable Version  3,527 / 9
Floor1 flyhighxu Posted 2008-03-30 15:14
初级用户 Posts 11 Credits 32
Example:
There are two batch files, a.bat and b.bat.
Using call b.bat or start b.bat in a.bat to realize calling and running b.bat when running a.bat.
Then, what is the difference between using call and start here? Thanks
Floor2 bat-zw Posted 2008-03-30 15:21
金牌会员 Posts 1,276 Credits 3,105
call generally calls commands within the batch script itself, such as:

for /l %%i in (1,1,3) do call :run

...........................................

:run
start b.bat
goto :eof

...........................................

That is to call b.bat three times.

And start can only be used to call external commands of the batch script, such as:

for /l %%i in (1,1,3) do start b.bat

Also calls b.bat three times.

For example:

set /a str=%random%%%10
if %str% geq 5 start b.bat

...........................................

As long as the condition is met (%str% >= 5), b.bat is called.

[ Last edited by zw19750516 on 2008-3-30 at 03:26 PM ]
Floor3 knoppix7 Posted 2008-03-30 18:31
银牌会员 Posts 634 Credits 1,287 From cmd.exe
call 继承当前的变量,变量可传递到父bat

call Inherits the current variables, and variables can be passed to the parent bat
Floor4 Shinaterry Posted 2008-03-30 19:08
初级用户 Posts 51 Credits 97
Floor5 knoppix7 Posted 2008-03-30 21:17
银牌会员 Posts 634 Credits 1,287 From cmd.exe
start is generally used for starting simultaneously.
However, it's very difficult to pass variables between 2 cmd directly. So it's rarely used..

But for something like debug command that can take a text file as input, start is very useful.
start a debug <r:\debug.txt
Then the parent BAT can directly echo a 100>>r:\debug.txt and so on. It's much more convenient than starting debug repeatedly
Floor6 flyhighxu Posted 2008-03-31 00:00
初级用户 Posts 11 Credits 32
Originally posted by zw19750516 at 2008-3-30 03:21 PM:
call is generally used to call commands within the batch itself, such as
for /l %%i in (1,1,3) do call :run
...........................................
:run
start b.bat
goto :eof
............ ...


Thanks, but besides calling commands within the batch itself, call can also call external commands. Does that mean that in terms of calling external commands, both call and start can be used, and their functions overlap?
Floor7 bat-zw Posted 2008-03-31 02:16
金牌会员 Posts 1,276 Credits 3,105
Originally posted by flyhighxu at 2008-3-31 00:00:


Thanks, but call can not only call the commands in the batch itself, but also call external commands. Does it mean that in terms of calling external commands, call and start are both applicable, and their functions overlap?

Both call and start can be used to call external commands of batch processing, but there are still differences in functions. Call is an internal command of batch processing. It can pass batch processing variables to external programs (usually batch processing), and can also start executable programs on cmd. While start is a built-in command of cmd. Its function is only to start a certain executable program, and it cannot pass batch processing variables to the outside. In this respect, call is more powerful than start. For example:
 a.bat

The function of a.bat is to start b.bat three times and pass the variable %%i to b.bat
 b.bat

b.bat is to display the number passed from a.bat each time

[ Last edited by zw19750516 on 2008-3-31 at 02:30 AM ]
Floor8 flyhighxu Posted 2008-03-31 11:08
初级用户 Posts 11 Credits 32
Thank you very much. It's very detailed and clear.
Floor9 cyn01livecn Posted 2010-12-10 17:13
初级用户 Posts 23 Credits 28
Why doesn't this command work? (I'm a beginner)
Floor10 ingxii Posted 2010-12-28 20:53
新手上路 Posts 8 Credits 9
Today I found a very important difference between them.
start returns immediately.
cal waits until the called program finishes before returning.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023