2015-08-27 48 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>