简体   繁体   English

如何将参数从 Windows 命令提示符传递到 Kitchen.bat (Pentaho)?

[英]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).我创建了一个 Windows cmd 文件test.cmd ,它期望将两个参数传递给Kitchen.bat (Pentaho)。

  2. I call test.cmd in Windows command line by passing two parameters: test.cmd 1 2我通过传递两个参数在 Windows 命令行中调用test.cmdtest.cmd 1 2

  3. In Spoon (designer), I write the two parameters to a log file.Spoon (设计器)中,我将两个参数写入日志文件。

After the job completed, I still seeing the variable itself instead of the value (1 2) that I have passed.作业完成后,我仍然看到变量本身,而不是我传递的值 (1 2)。

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.首先,我怀疑bat文件中的“param”有问题(它获取值并传递给kitchen.bat),所以我用谷歌搜索并尝试了所有可能的解决方案,下面是我尝试过的。

"-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 :测试.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 : Windows 命令行

Window Command Line Image窗口命令行图像

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

Pentaho KJB : Pentaho KJB :

Pentaho KJB Image Pentaho KJB 图像

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).显示变量本身而不是实际值 (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.命名参数:您可以在 KJB/KTR 中设置一个参数,并通过 CMD 调用将值传递给这些参数。

In your KTR/KJB Configurations, go to the Parameter tab and set your desired parameters names.在您的 KTR/KJB 配置中,转到“参数”选项卡并设置所需的参数名称。 在此处输入图片说明

In this case i set a Default value of 1 for A and 2 for B, you should leave the default values blank.在这种情况下,我将 A 的默认值设置为 1,B 的默认值设置为 2,您应该将默认值留空。

CMD Call : This documentation should have all the information you need. CMD Call此文档应包含您需要的所有信息。 Thou in your case i see you're attempting to set the 2 variables before the KJB/KTR call.你在你的情况下,我看到你试图在 KJB/KTR 调用之前设置 2 个变量。 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.我个人在我的批处理命令中使用 %VAR% 调用来引用 Windows 中的系统/环境变量,它们工作得很好,我不知道在运行时设置变量是否适用于 Pentaho,因为你是为您的 -param 命令的值传递一个“文字”,所以我认为 CMD 不会解析 %A% 或 %B%,因为它用引号括起来。

That said, there are many ways within Pentaho to resolve variables and set them on Run time.也就是说,Pentaho 中有很多方法可以解析变量并在运行时设置它们。

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.你的情况可能是你没有在你的 KJB/KTR 的配置中设置参数,所以在调用时,它没有找到 A 或 B,它只是打印 ${A} amd ${B} 因为没有参数已设置,因此未解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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