0

Creating a batch utility script on Windows 7 to invoke an executable. It essentially works, EXCEPT that my second IF statement. Tried a number of different things.

My intent is to invoke 'DoSomething' for each command line argument. That part works! The second IF statement prints a help message only if there no parameters given on the command line. Well, that's the intent. That's not what it's doing.

@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
)

Ideas?

1 Answer 1

1

Tried with these changes and seems to work as expected

@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
)

The first obvious error is the label :Start before the setting to false. Then to refer to the value of a variable you need to enclose the variable in %

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.