【问题标题】:Batch Method with Argument带参数的批处理方法
【发布时间】:2015-08-27 21:00:23
【问题描述】:

有没有办法将参数放入批处理脚本中的方法中?我知道我可以在 Java 编程中做到这一点。

示例 #1 (Java)

public class Test {

  public static void main (String [] args) {
    Test t1=new Test();
    System.out.print(t1.method1(false));
  }

  public int method1 (boolean val1) {

    if (val1==false) {
      return 0;}
    else {
      return 1;}
    }

  }

我想要这样的东西,所以当方法运行时,根据参数,方法会产生不同的结果。

示例 #2(批处理 - 部分伪代码)

:method1
::With an argument a1 (by default a1=1)
if %a1%==1 echo Option #1
if %a1%==2 echo Option #2

所以当我调用 method1 时,根据参数,我可能有两个结果。 有没有办法做到这一点?或者关于一种方法如何产生不同结果的建议?谢谢

【问题讨论】:

  • 我投票结束这个问题,因为 OP 显然懒得做最基本的研究
  • 刚刚搜索了问题标题,答案/教程/示例在前 10 个结果中...

标签: variables batch-file cmd


【解决方案1】:

尝试call 内置语句的内联帮助。

C:\>call /?
Calls one batch program from another.

CALL [drive:][path]filename [batch-parameters]

  batch-parameters   Specifies any command-line information required by the
                     batch program.

If Command Extensions are enabled CALL changes as follows:

CALL command now accepts labels as the target of the CALL.  The syntax
is:

    CALL :label arguments

A new batch file context is created with the specified arguments and
control is passed to the statement after the label specified.  You must
"exit" twice by reaching the end of the batch script file twice.  The
first time you read the end, control will return to just after the CALL
statement.  The second time will exit the batch script.  Type GOTO /?
for a description of the GOTO :EOF extension that will allow you to
"return" from a batch script.

<continutes>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 2019-04-15
    • 2015-08-21
    • 2020-03-01
    相关资源
    最近更新 更多