2015-08-27 31 views
-3

有没有办法将参数放入批处理脚本中的方法中?我知道我可以在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 

因此,当我打电话方法1,根据不同的参数,我可以有两个结果。 有没有办法做到这一点?或者建议如何一种方法可以有不同的结果? Thanx

+2

我投票关闭这个问题,因为OP显然是懒得做,即使是最基础研究 – Paul

+0

只是一派问题标题和答案/教程/例子是前10名的结果... – wOxxOm

回答

0

尝试使用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>