2012-10-03 101 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

相关问题