Shell Command in knime

Hello all Knimian,

I want to run a shell command in a loop. Can anyone suggest me any workflow or Nodes to use this purpose !!! urgently needed alll....

Thanks...all

Im using a java snippet for simple shell calls, e.g. like (here windows/linux version):

import java.io.BufferedReader;
import java.io.InputStreamReader;
//*******************
boolean isWindows=c_knimework.charAt(0)!='/';

out_ResultMessage="";
out_ResultCode=1;

String call="some call from somewhere";

ProcessBuilder pb =null;
if (isWindows){
        //modify for windows if needed
 pb = new ProcessBuilder("cmd","/C",call);}
else{
       //modify for linux if needed
 pb = new ProcessBuilder("bash","-c",call);
 }
 
pb.redirectErrorStream(true);
        try {
            Process p = pb.start();
            String s;
            // read from the process's combined stdout & stderr
            BufferedReader stdout = new BufferedReader(
                new InputStreamReader(p.getInputStream()));
            while ((s = stdout.readLine()) != null) {
                out_ResultMessage+=s;
            }
            out_ResultCode= p.waitFor();
            p.getInputStream().close();
            p.getOutputStream().close();
            p.getErrorStream().close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
out_Call = call;

 

 

1 Like

What about the External Tool Node?

1 Like

Hi

 

There is a BASH node in the NGS node collection. Maybe that helps?

https://tech.knime.org/community/next-generationsequencing

We generated a CSH node for our internal systems, but at the end it is based on the above mentioned BASH node.

But be careful when using these node. Normally they just work in a very specific setup within your infrastructure. That can just be a workaround.

Frank

 

Thanks...All.....

For Superfast Reply!!!

@thor

For me the external toolnode always had the problem that it expected some input/output files. Just calling some commands didnt seem possible without any weird hacks. Generating some XML/XLS files (to be used together with a reader node for this file format) is not possible this way either.

@frank

that sounds interesting. As its called "bash"-node... is it supporting windows too by any chance? Choosing a linux KNIME server with windows clients complicates things unfortunately. 

Please add java snippet node in knime process(knwf)).
Because I have never used java snippet node before.

Hi there @omeralitopal,

are you interested about using Java Snippet for shell command in KNIME?

To check workflow examples of Java Snippet check its description on KNIME Hub. At bottom you will find them listed.

Br,
Ivan

are you interested about using Java Snippet for shell command in KNIME? >> Yes, exactly

I check this article but please how to write shell script using java sinppet example. Because I have never used java snippet node before. Thanks

You can also try the Bash node to invoke an external shell. Others here on the forum have had success with that in the past.

1 Like

Hi @omeralitopal,

you are proficient in Java or? Anyways I would follow @ScottF advice :wink:

Br,
Ivan

Hi @Benjamin_Dosch,

I tried running your code as I running into several issues with the Bash Node we are tryign work work around in this post:

However, I can’t get your code running. It always gives nothing back. Do you or anyone else can spot any mistake at first glance?

Many thanks in advance
Mike

Hi @mwiegand

You are replying to someone that has not been online for 8 years. Likeliness to get a response is not very high. Moreover, that was quite a few KNIME versions ago. I would recommend creating a new topic in case you have a question or issue.

4 Likes