China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 13:48
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please tell me the difference between call and start when calling files? View 3,420 Replies 9
Original Poster Posted 2008-03-30 15:14 ·  中国 北京 海淀区 联通
初级用户
Credits 32
Posts 11
Joined 2008-03-08 22:19
18-year member
UID 112424
Gender Male
Status Offline
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
Floor 2 Posted 2008-03-30 15:21 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
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 ]
批处理之家新域名:www.bathome.net
Floor 3 Posted 2008-03-30 18:31 ·  中国 北京 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
call 继承当前的变量,变量可传递到父bat

call Inherits the current variables, and variables can be passed to the parent bat
Floor 4 Posted 2008-03-30 19:08 ·  中国 广东 珠海 电信
初级用户
★★
Credits 97
Posts 51
Joined 2008-03-19 15:26
18-year member
UID 113404
Gender Male
Status Offline
Floor 5 Posted 2008-03-30 21:17 ·  中国 北京 联通
银牌会员
★★★
Credits 1,287
Posts 634
Joined 2007-05-02 15:06
19-year member
UID 87277
Gender Male
From cmd.exe
Status Offline
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
Floor 6 Posted 2008-03-31 00:00 ·  中国 北京 海淀区 联通
初级用户
Credits 32
Posts 11
Joined 2008-03-08 22:19
18-year member
UID 112424
Gender Male
Status Offline
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?
Floor 7 Posted 2008-03-31 02:16 ·  中国 湖南 株洲 电信
金牌会员
★★★★
永远的学习者
Credits 3,105
Posts 1,276
Joined 2008-03-08 13:00
18-year member
UID 112398
Gender Male
Status Offline
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
for /l %%i in (1,1,3) do call b.bat %%i
goto :eof

The function of a.bat is to start b.bat three times and pass the variable %%i to b.bat
 b.bat
echo number is %1&goto :eof

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 ]
批处理之家新域名:www.bathome.net
Floor 8 Posted 2008-03-31 11:08 ·  中国 北京 光环新网
初级用户
Credits 32
Posts 11
Joined 2008-03-08 22:19
18-year member
UID 112424
Gender Male
Status Offline
Thank you very much. It's very detailed and clear.
Floor 9 Posted 2010-12-10 17:13 ·  中国 上海 东方有线
初级用户
Credits 28
Posts 23
Joined 2010-11-26 11:37
15-year member
UID 178303
Gender Male
Status Offline
Why doesn't this command work? (I'm a beginner)
Floor 10 Posted 2010-12-28 20:53 ·  中国 广东 广州 白云区 电信
新手上路
Credits 9
Posts 8
Joined 2010-11-19 09:47
15-year member
UID 177845
Gender Male
Status Offline
Today I found a very important difference between them.
start returns immediately.
cal waits until the called program finishes before returning.
Forum Jump: