像在批处理文件中的函数/方法? [英] Something like a function/method in batch files?

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

问题描述

有什么,mimicks的方法像一个来自Java和C#等,知道了吗?我有一个批处理文件,5条线的命令,那些5线在批处理文件内多个地方使用。我不能使用goto语句,因为这取决于那些5行创建的错误级别我有遵循不同的动作。我试图把我的5行的批处理文件5lines.bat内,但原批处理文件original.bat只要求5lines.bat和调用5lines.bat后不执行命令):这是我怎么看起来original.bat这样的:

is there anything that mimicks a method like one knows it from Java, C# etc.? I have 5 lines of commands in a batch file, those 5 lines are used at more than one place inside the batch file. I can't use a goto, because depending on the errorlevel created by those 5 lines I have different actions that follow. I tried putting my 5 lines inside a batch file 5lines.bat, but the original batch file original.bat only calls 5lines.bat and doesn't execute the commands after the call to 5lines.bat ): That's how my original.bat looks like:

5lines.bat
echo this gets never called, how to make sure this gets called?

有没有退出或5lines.bat这样的事情!我怎样才能确保行5lines.bat被调用后?

There's no exit or something like this in 5lines.bat! How can I make sure the line after 5lines.bat gets called?

推荐答案

配售可重复使用的功能整合到一个单独的批处理文件,肯定会工作,以模拟功能。

Placing the reusable functions into a separate batch file would certainly work to simulate a function.

美中不足的是,你必须使用顺序呼叫命令,以确保控制返回给调用者的第二个批处理文件执行完毕后再。

The catch is that you have to use the call command in order to ensure that control returns to the caller after the second batch file finishes executing.

call 5lines.bat
echo this will now get called

这篇关于像在批处理文件中的函数/方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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