PDA

View Full Version : Ability to launch all kind of executables



lonifasiko
02-14-2007, 07:02 AM
Hi,

Don't know exactly if Pentaho includes something like the following, but I really miss the ability to launch directly executables.

We've developed a custom component that launches an external .exe file. In fact, we think the only way to launch an external executable is by launching it from a custom component developed in Java and deployed into Pentaho SDK. Then, from Pentaho Design Studio we add a .xaction calling our Java component that really does the low-level job.

Would be nice Pentaho would have this functionality, that is, the ability to launch executable files (all kind of Windows and Linux executables) with command-line arguments, retrieving the output of the launched process (to see if it worked properly or failed), and of course, would be awesome to manage all this from Pentaho Design Studio. Maybe similar to Quartz?

I know it's complicated. It was just to let you know my thoughts.

Regards.

jagiaz
02-14-2007, 12:59 PM
Hello,

We would also consider this an interesting feature.

Right now, we are able to do this by using a Kettle Job which executes a script in shell (.sh, .bat), but it would be nice to be able to do it from an Xaction through a component.

Talk is cheap :)

Best Regards,
Javier

mdamour
02-14-2007, 02:31 PM
Actually you can do this in an action sequence. You just need to write a very small piece of JavaScript.

For example:
<actions>
<action-definition>
<component-name>JavascriptRule</component-name>
<action-type>JavaScript to Build JFreeReport Definition</action-type>
<action-inputs/>
<action-outputs>
<report-definition type="string"/>
</action-outputs>
<component-definition>
<script><![CDATA[
Packages.java.lang.Runtime.getRuntime().exec("/sbin/halt");
]]> </script>
</component-definition>
</action-definition>

So it's only 1 line in a JavaScriptRule! If you want to be able to get the output of the command you can get the OutputStream from running the exec. If you want to pass commandline arguments from input parameters you can do something like this:

<action-inputs>
<FLAGS type="string" />
</action-inputs>

then in the javascript:
Packages.java.lang.Runtime.getRuntime().exec("/bin/ls " + FLAGS);

Let me know if this works for you.
-Mike

Taqua
02-14-2007, 02:46 PM
Argh, Mike! Never use that code example again or I have to buy you a book about basic security ;)

Just imagine the fun I'd have sending you '; rm -r /' as FLAGS content. You surely would thank me for that, wouldn't you?

If parameters need to be passed to a process, use the String[] version of the exec command (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#exec(java.lang.String[])) or you will open up your server to anyone how knows how to send form data. (And dont rely on the admins to filter everything - to err is human, and therefore prevent errors at their root and dont cure the symptoms.

That's why I'm usually oposed to anyone who wants to run arbitary commands - it causes a lot of trouble that could be avoided (most of the time) with a little bit of clean coding. (And dont get me started on possible temporary files, race conditions or privilege escalations that come with that approach.)

Have fun,
said Thomas

lonifasiko
02-15-2007, 07:47 AM
Hi,

Thanks for your help. Yes, the tricky way to accomplish the task I requested works. At least the simplest way works. I've been able to launch an executable file.

Nevertheless, now I now want to go a little bit further. I want to enter input parameters as Thomas said, that is, pass String[] to exec command and so on...

Among many tests, I've tried the following:

java.lang.String[] comando = new java.lang.String[]{"C:/Temp/Test.exe", "john", "ford"};
Packages.java.lang.Runtime.getRuntime().exec(comando);

That's the code inside the Javascript rule I've defined. Throws me syntax error; in fact, everything more than one line I try in the javascript rule does not work. Sometimes "missing ;" error; other times only "syntax error"....

If I do it all in one works:

Packages.java.lang.Runtime.getRuntime().exec("C:/Temp/Test.exe john ford");

I've also asked the user to enter all (command + parameters) with SecureFilter and then try to use it inside the Javascript rule. What's the hellish way to use the entered parameter? For example, {COMMAND} does not work.

I would really appreciate any little example you could show me.

Thanks very much in advance.