为什么不叫prepending&QUOT嵌套的批处理文件,调用"到线退出父批处理文件? [英] Why does calling a nested batch file without prepending "call" to the line exit the parent batch file?

查看:105
本文介绍了为什么不叫prepending&QUOT嵌套的批处理文件,调用"到线退出父批处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何从父文件中使用呼叫命令嵌套调用批处理文件,因为有很多资源上:

I understand how to call nested batch files from within a parent file using the call command, as there are plenty of resources on that:

  • http://www.robvanderwoude.com/call.php
  • http://ss64.com/nt/call.html
  • bat-file termination

不过,我不明白的为什么调用另一个批处理文件从另一个终止父。

However, I don't understand why calling another batch file from another terminates the parent.

有关一个不太抽象的例子,假设我有一个批处理文件,链接在一起的独立批处理文件和我错误地没prePEND 呼叫每行

For a less abstract example, suppose I have a batch file that "links" together separate batch files and I erroneously didn't prepend call to each line:

foo.bat
bar.bat

这将只执行foo.bat,然后退出。要正确执行这两个命令,我不得不prePEND每次调用语句之前:

This would only execute foo.bat and then exit. To correctly execute both commands, I would have to prepend call before each statement:

call foo.bat
call bar.bat

为什么第一个功能还存在吗?为什么它没有被改变?我注意到,呼叫在MS-DOS 3.3,这是在80年代末引进发行,所以这个功能还在这里反向兼容性如何?我想不出任何(实际)用法,但也许我太习惯新的编程技术。

Why does the first functionality still exist? Why hasn't it been changed? I noticed that call was introduced in MS-DOS 3.3, which was released in the late 80s, so is this functionality still here for reverse compatibility? I can't think of any (practical) usages of it, but perhaps I'm too used to "new" programming techniques.

推荐答案

DOS使用简单的文本处理(回来时,你有喜欢的东西 FILES = 20 CONFIG.SYS中来允许的 20 的文件句柄),所以打开文件,读取下一行,关闭该文件,然后执行刚读线。如果该文件被称为另一个,则处理继续与该文件,所以只有1文件句柄将需要一个批处理文件。

DOS used simple text processing (back when you had things like FILES=20 in config.sys to allow 20 file handles), so opened the file, read the next line, closed the file, then executed the line just read. If the file called another, then the processing continued with that file, so only 1 file handle would be required for a batch file.

直到微软把在呼叫命令,没有办法找回原来的文件(不使用小把戏,比如给previous文件的名称作为一个参数,以及使用临时文件,让原始批处理文件知道它有圆顶一些处理,并且可以再 GOTO 该文件的下一部分)。

Until Microsoft put in the call command, there was no way to get back to the original file (without using tricks like giving the name of the previous file as a parameter, and using temporary files to let the original batch file know it had dome some processing, and could then GOTO the next part of the file).

这篇关于为什么不叫prepending&QUOT嵌套的批处理文件,调用"到线退出父批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆