Striim 3.9.4 / 3.9.5 documentation

Calling a shell script from a custom Java function

The following custom function will call a shell script specified in TQL.

import com.webaction.runtime.compiler.custom.Nondeterministic; 

public static int kickShell (String args) {
        int ret = 0;
        try {
            if (args.indexOf(".sh") == -1) {
                System.out.println("Error:" + args + " is not shell.");
                return ret;
            Process process = new ProcessBuilder("sh", args).start();
            ret = process.waitFor();
            System.out.println("return:" + ret);
        }catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Info: Please specify one argument.");
            System.out.println("return:" + ret);
        }catch (Exception e){
            System.out.println("return:" + ret);
            return ret;

You could use that in TQL as follows:

SELECT kickShell('/etc/striim/') as retVal ...

import com.webaction.runtime.compiler.custom.Nondeterministic; and @Nondeterministic cause the script to be executed every time the CQ is run. Without those lines, the script would be called only once, on deployment.


Consider the potential security issues of allowing TQL applications to call scripts on the Striim host system. Depending on your environment and requirements, it may be more appropriate to call a specific script from the custom Java function.