 <p>Here is an example to do it somewhat like using pipes, the script is embedded in java in this example.</p> <pre><code>import java.io.*; class junk { public static void main (String args[]) { try { String line; String script; OutputStream stdin = null; InputStream stderr = null; InputStream stdout = null; Process p = Runtime.getRuntime ().exec ("/bin/bash"); stdin = p.getOutputStream (); stderr = p.getErrorStream (); stdout = p.getInputStream (); script = "a=$(cat &lt;&lt;'@@@'\n" + "ICAgICBfCiAgICB8IHwgX18gX19fICAgX19fXyBfICAgIF9fXyBfXyBfIF8gX18gICAgXyBfXyBfICAg" + "XyBfIF9fCiBfICB8IHwvIF9gIFwgXCAvIC8gX2AgfCAgLyBfXy8gX2AgfCAnXyBcICB8ICdfX3wgfCB8" + "IHwgJ18gXAp8IHxffCB8IChffCB8XCBWIC8gKF98IHwgfCAoX3wgKF98IHwgfCB8IHwgfCB8ICB8IHxf" + "fCB8IHwgfCB8CiBcX19fLyBcX18sX3wgXF8vIFxfXyxffCAgXF9fX1xfXyxffF98IHxffCB8X3wgICBc" + "X18sX3xffCB8X3wKICAgICAgICAgICAgICAgICAgICBfICAgICAgICAgICAgICAgXwogICAgICAgICAg" + "ICAgICAgICAgfCB8X18gICBfXyBfIF9fX3wgfF9fCiAgICAgICAgICAgICAgICAgICB8ICdfIFwgLyBf" + "YCAvIF9ffCAnXyBcCiAgICAgICAgICAgICAgICAgICB8IHxfKSB8IChffCBcX18gXCB8IHwgfAogICAg" + "ICAgICAgICAgICAgICAgfF8uX18vIFxfXyxffF9fXy9ffCB8X3wK" + "\n" + "@@@)\n" + "st=0\n" + "for (( i=0; i&lt;\"${#a}\"; i++ ))\n" + "do\n" + " x=${a:$i:1}\n" + " in=$(($(expr index \\\n" + " 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' \"\\\\$x\")-1))\n" + " if [ $in -ge 0 ]; then case $st in\n" + " 0 ) out=$(($in&lt;&lt;2)); st=3;;\n" + " 1 ) out=$(($out|$in)); \n" + " printf \\\\$(printf '%03o' $(($out&amp;255)) ) ; st=0 ;;\n" + " 2 ) out=$(($out+($in&gt;&gt;2))); \n" + " printf \\\\$(printf '%03o' $(($out&amp;255)) ) ;\n" + " st=0; out=$(($in&lt;&lt;6)); st=1;;\n" + " * ) out=$(($out+($in&gt;&gt;4))); \n" + " printf \\\\$(printf '%03o' $(($out&amp;255)) ) ;\n" + " st=0; out=$(($in&lt;&lt;4)); st=2;;\n" + " esac fi\n" + "done\n"; stdin.write (script.getBytes ()); stdin.close (); BufferedReader br = new BufferedReader (new InputStreamReader (stdout)); while ((line = br.readLine ()) != null) { System.out.println(line); } br.close (); br = new BufferedReader (new InputStreamReader (stderr)); while ((line = br.readLine ()) != null) { System.out.println ("2&gt;" + line); } br.close (); p.waitFor (); System.out.println ("exit code " + p.exitValue ()); } catch (IOException e) { e.printStackTrace (); } catch (java.lang.InterruptedException e) { e.printStackTrace (); } } } </code></pre>