Search code examples
batch-filedatastage

Dynamic Command Generation in Batch


i'm trying to generate a dynamic command for datastage using a bat file, but i think i'm missing something.

The command "variation" is taken by reading a .txt file.

Here the code:

SET PATH_Classic=C:\IBM\InformationServer\Clients\Classic
CD %PATH_Classic%
SET /P INV_ID=Type the invocation ID : 
ECHO %INV_ID%
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%G in (%1) do (
SET FLOW=%%G
SET JOBNAME=****_****_**_***_%FLOW%_***_***.%INV_ID%
SET STAGENAME=ReadFile_%FLOW%
dsjob -domain NONE -user ******* -password ******* -server ****** -linkinfo ****** %JOBNAME% %STAGENAME% read_file_IN
)
pause

I had to keep some info private (*** stuff), but the logic doesn't change.

The problem seems to be that the variables FLOW, JOBNAME & STAGENAME are not being setted.


Solution

  • You enabled delayed expansion, but you also have to actually use it, like !Variable! rather than %Variable%. Here is the fixed code (I also improved some quotation-mark-related issues):

    set "PATH_Classic=C:\IBM\InformationServer\Clients\Classic"
    cd /D "%PATH_Classic%"
    set /P "INV_ID=Type the invocation ID: "
    echo %INV_ID%
    setlocal EnableDelayedExpansion
    for /F "usebackq tokens=* delims= " %%G in ("%~1") do (
        set "FLOW=%%G"
        set "JOBNAME=****_****_**_***_!FLOW!_***_***.%INV_ID%"
        set "STAGENAME=ReadFile_!FLOW!"
        dsjob -domain NONE -user ******* -password ******* -server ****** -linkinfo ****** !JOBNAME! !STAGENAME! read_file_IN
    )
    endlocal
    pause