在另一个批处理文件中访问批处理功能 [英] Accessing Batch Functions in another batch file

查看:54
本文介绍了在另一个批处理文件中访问批处理功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,可以说我们有一个名为"lib.cmd"的文件

Alright, so lets say we have a file called "lib.cmd" it contains

@echo off
GOTO:EXIT

:FUNCTION
     echo something
GOTO:EOF

:EXIT
exit /b

然后我们有一个名为"init.cmd"的文件

Then we have a file called "init.cmd" it contains

@echo off

call lib.cmd

反正init.cmd内是否可以访问:FUNCTION?就像bash如何使用源代码"一样,也要在同一进程中运行另一个bash文件.

Is there anyway to access :FUNCTION inside of init.cmd? Like how bash uses "source" too run another bash file into the same process.

推荐答案

将您的 lib.cmd 更改为以下形式;

Change your lib.cmd to look like this;

@echo off
call:%~1
goto exit

:function
     echo something
goto:eof

:exit
exit /b

然后传递给批处理文件(%〜1 )的第一个参数将标识为您要调用的函数,因此将使用 call:%〜1 ,现在您可以通过以下方式在 init.cmd 中调用它:

Then the first argument passed to the batch file (%~1) will identify as the function you want to call, so it will be called with call:%~1, and now you can call it in init.cmd in this way:

call lib.cmd function

这篇关于在另一个批处理文件中访问批处理功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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