2012-10-03 57 views
0

在Windows 7上創建批處理實用程序腳本以調用可執行文件。它本質上是有效的,除了我的第二個IF聲明。嘗試了許多不同的事情。在Windows批處理文件中設置和測試變量

我的意圖是爲每個命令行參數調用'DoSomething'。這部分工作! 僅當沒有在命令行上給出參數時,第二個IF語句纔會打印幫助消息。那麼,這是意圖。這不是它在做什麼。

@ECHO OFF 

:Start 
SET a_file_was_processed="false" 
IF "%1" NEQ "" (
    SET a_file_was_processed="true" 
    ECHO Extracting table %1 from database. 
    DoSomething word%1 > output_%1.txt 
    ECHO Finished extract table to file output_%1.txt 
SHIFT 
GOTO Start 
) 

if a_file_was_processed NEQ "true" (
    ECHO Invoke this script as: Extract_From_sdf table_name1 table_name2 
) 

想法?

回答

1

試圖用這些變化,似乎預期

@ECHO OFF 

SET a_file_was_processed="false" 
:Start 
IF "%1" NEQ "" (
    SET a_file_was_processed="true" 
    ECHO Extracting table %1 from database. 
    rem --- DoSomething word%1 > output_%1.txt 
    ECHO Finished extract table to file output_%1.txt 
SHIFT 
GOTO Start 
) 

if %a_file_was_processed% NEQ "true" (
    ECHO Invoke this script as: Extract_From_sdf table_name1 table_name2 
) 

第一個明顯的錯誤是在標籤的工作:設置爲false之前啓動。 然後要引用變量的值,您需要將該變量包含在%

+0

非常好,謝謝 – elbillaf

相關問題