# Shell Command in knime

**URL:** <https://forum.knime.com/t/shell-command-in-knime/6709>\
**Category:** KNIME Analytics Platform\
**Created:** [September 26, 2014, 9:07am UTC](https://forum.knime.com/t/shell-command-in-knime/6709 "2014-09-26T09:07:59Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![recervictory](https://forum-cdn.knime.com/user_avatar/forum.knime.com/recervictory/32/272_2.png) [@recervictory](https://forum.knime.com/u/recervictory)\
**Post date:** [September 26, 2014, 9:07am UTC](https://forum.knime.com/t/shell-command-in-knime/6709/1 "2014-09-26T09:07:59Z")

</div>

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

 ![](http://img4.wikia.nocookie.net/__cb20140405142308/parody/images/5/59/Mandark.jpg)

---

<div class="post-metadata">

**Author:** ![Benjamin\_Dosch](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/d9b06d/32.png) [@Benjamin\_Dosch](https://forum.knime.com/u/Benjamin_Dosch)\
**Post date:** [September 26, 2014, 10:25am UTC](https://forum.knime.com/t/shell-command-in-knime/6709/2 "2014-09-26T10:25:55Z")

</div>

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;
```

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![thor](https://forum-cdn.knime.com/user_avatar/forum.knime.com/thor/32/4_2.png) [@thor](https://forum.knime.com/u/thor)\
**Post date:** [September 26, 2014, 10:40am UTC](https://forum.knime.com/t/shell-command-in-knime/6709/3 "2014-09-26T10:40:39Z")

</div>

What about the External Tool Node?

---

<div class="post-metadata">

**Author:** ![frank](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/f/3d9bf3/32.png) [@frank](https://forum.knime.com/u/frank)\
**Post date:** [September 26, 2014, 11:21am UTC](https://forum.knime.com/t/shell-command-in-knime/6709/4 "2014-09-26T11:21:46Z")

</div>

Hi

&nbsp;

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

[https://tech.knime.org/community/next-generationsequencing](https://forum.knime.com/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&nbsp;within your infrastructure. That can just be a workaround.

Frank

&nbsp;

---

<div class="post-metadata">

**Author:** ![recervictory](https://forum-cdn.knime.com/user_avatar/forum.knime.com/recervictory/32/272_2.png) [@recervictory](https://forum.knime.com/u/recervictory)\
**Post date:** [September 26, 2014, 12:13pm UTC](https://forum.knime.com/t/shell-command-in-knime/6709/5 "2014-09-26T12:13:04Z")

</div>

**Thanks...All.....**

**For Superfast Reply!!!**

---

<div class="post-metadata">

**Author:** ![Benjamin\_Dosch](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/b/d9b06d/32.png) [@Benjamin\_Dosch](https://forum.knime.com/u/Benjamin_Dosch)\
**Post date:** [September 26, 2014, 4:26pm UTC](https://forum.knime.com/t/shell-command-in-knime/6709/6 "2014-09-26T16:26:56Z")

</div>

@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.&nbsp;

---

<div class="post-metadata">

**Author:** ![omeralitopal](https://forum-cdn.knime.com/user_avatar/forum.knime.com/omeralitopal/32/3061_2.png) [@omeralitopal](https://forum.knime.com/u/omeralitopal)\
**Post date:** [March 8, 2020, 6:55pm UTC](https://forum.knime.com/t/shell-command-in-knime/6709/7 "2020-03-08T18:55:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ipazin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/ipazin/32/806_2.png) [@ipazin](https://forum.knime.com/u/ipazin)\
**Post date:** [March 9, 2020, 5:36pm UTC](https://forum.knime.com/t/shell-command-in-knime/6709/8 "2020-03-09T17:36:23Z")

</div>

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](https://kni.me/n/QNB4FsAPnEAgOMVh) on KNIME Hub. At bottom you will find them listed.

Br,  
Ivan

---

<div class="post-metadata">

**Author:** ![omeralitopal](https://forum-cdn.knime.com/user_avatar/forum.knime.com/omeralitopal/32/3061_2.png) [@omeralitopal](https://forum.knime.com/u/omeralitopal)\
**Post date:** [March 9, 2020, 8:21pm UTC](https://forum.knime.com/t/shell-command-in-knime/6709/9 "2020-03-09T20:21:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ScottF](https://forum-cdn.knime.com/user_avatar/forum.knime.com/scottf/32/61316_2.png) [@ScottF](https://forum.knime.com/u/ScottF)\
**Post date:** [March 9, 2020, 8:36pm UTC](https://forum.knime.com/t/shell-command-in-knime/6709/10 "2020-03-09T20:36:22Z")

</div>

You can also try the [Bash](https://kni.me/n/U2uB-qIId1RRfj0Y) node to invoke an external shell. Others here on the forum have had success with that in the past.

---

<div class="post-metadata">

**Author:** ![ipazin](https://forum-cdn.knime.com/user_avatar/forum.knime.com/ipazin/32/806_2.png) [@ipazin](https://forum.knime.com/u/ipazin)\
**Post date:** [March 10, 2020, 10:38am UTC](https://forum.knime.com/t/shell-command-in-knime/6709/11 "2020-03-10T10:38:48Z")

</div>

Hi @omeralitopal,

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

Br,  
Ivan

---

<div class="post-metadata">

**Author:** ![mwiegand](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mwiegand/32/66896_2.png) [@mwiegand](https://forum.knime.com/u/mwiegand)\
**Post date:** [October 18, 2022, 7:23pm UTC](https://forum.knime.com/t/shell-command-in-knime/6709/12 "2022-10-18T19:23:43Z")

</div>

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:

> [@Bash Node: Command not found](https://forum.knime.com/t/bash-node-command-not-found/46256/17):
>
> Just for completeness, I rebooted but it did not have any effect. I tried setting the PATH variable in Knime but it failed with Execute failed: Cannot execute command as well. I think the only two options left at present are to: Create a shell script, which could get done via Knime, and make it executable OR Using Java to make bash calls like in [Shell Command in knime](https://forum.knime.com/t/shell-command-in-knime/6709) While attempting the two options I encountered an issue with approach #1. I can’t make the shell script executable. Setting …

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?

 ![Bildschirmfoto 2022-10-18 um 21.23.10](https://forum-cdn.knime.com/uploads/default/original/3X/b/a/ba6321687479b0316fab93eee41c666d839c55bc.jpeg)

Many thanks in advance  
Mike

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [October 18, 2022, 7:31pm UTC](https://forum.knime.com/t/shell-command-in-knime/6709/13 "2022-10-18T19:31:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Iris](https://forum-cdn.knime.com/user_avatar/forum.knime.com/iris/32/14_2.png) [@Iris](https://forum.knime.com/u/Iris)\
**Post date:** [October 19, 2022, 5:36am UTC](https://forum.knime.com/t/shell-command-in-knime/6709/14 "2022-10-19T05:36:59Z")

</div>


