简体   繁体   中英

How can I pass parameters from Windows command prompt to Kitchen.bat (Pentaho)?

My problem

  1. I have created a Windows cmd file test.cmd which is expecting two parameters to be passed to Kitchen.bat (Pentaho).

  2. I call test.cmd in Windows command line by passing two parameters: test.cmd 1 2

  3. In Spoon (designer), I write the two parameters to a log file.

After the job completed, I still seeing the variable itself instead of the value (1 2) that I have passed.

What I have tried?

Firstly, I doubt that the "param" in the bat file got problem (where it takes the value and pass to the kitchen.bat), so I googled and I have tried all the possible solution, below is what I tried.

"-param:A=%A%"
"/param:A=%A%" 
/param "A:%A%" 
'/param:"A=%A%"' 

Unfortunately, non of these are working.

Here is my source code

test.bat :

echo "Starting Job.."
echo "printing parameter.."
echo %1
echo %2

Set A=%1
Set B=%2
set LOG_PATH=C:\App\Reporter\Pentaho\Config\Utilities\Import.log
Set CONFIG_PATH=C:\App\Reporter\Pentaho\Config\Utilities

C:\App\REPORTER\Pentaho\Env\V8.2\kitchen.bat /file:"CONFIG_PATH"\test.kjb "/level=Basic" "/logfile=%LOG_PATH%" "-param:A=%A%" "-param:B=%B%"

pause

Windows command line :

Window Command Line Image

C:......>test.cmd 1 2

Pentaho KJB :

Pentaho KJB Image

I use "write to log" function to retrieve the value from the variable.

V1 = ${A}
V2 = ${B}

Here the result

Result Image

V1 = ${A}
V2 = ${B}

Showing variable itself instead of the actual values (1, 2).

A few things to take in mind.

Named Parameters : You can set a parameter in your KJB/KTR, and pass a value to those parameters through CMD call.

In your KTR/KJB Configurations, go to the Parameter tab and set your desired parameters names. 在此处输入图片说明

In this case i set a Default value of 1 for A and 2 for B, you should leave the default values blank.

CMD Call : This documentation should have all the information you need. Thou in your case i see you're attempting to set the 2 variables before the KJB/KTR call. I personally use %VAR% calls in my Batch commands to reference System/Ambient variables in Windows, and they work just fine, i don't know if setting the variable in run time works for Pentaho, due to the fact that you're passing a 'Literal' for the value of your -param command, so i think the CMD won't resolve %A% or %B%, since it's wrapped in quotes.

That said, there are many ways within Pentaho to resolve variables and set them on Run time.

Your case just might be that you didn't set the parameter in the configuration of your KJB/KTR, so upon call, it isn't finding A or B, it just prints ${A} amd ${B} because no parameter was set, and thus, not resolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM