title: Java: "UNIXProcess" error when using "exec" or "ProcessBuilder" to run a command
body: <p>I'm trying to run the command "/home/simulations/scripts/getDsuIp.sh" with no arguments. </p>
  
  <p>When I run this command manually on the machine, it works great! So the <strong>file is definitely there</strong>, is definitely <strong>runnable</strong> (755), and is under the <strong>same user</strong> (root) . The problem comes when I try to run a Java program that executes this file. <strong>I only see this problem on one machine</strong>, it works in other places, but I'd like to figure out why it's failing.</p>
  
  <h1>Running the process using ProcessBuilder</h1>
  
  <pre><code>ProcessBuilder pb = new ProcessBuilder("/home/simulations/scripts/getDsuIp.sh");
  Process p = pb.start();
  </code></pre>
  
  <p>This gives me the following error:</p>
  
  <pre><code>Exception in thread "main" java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
  Caused by: java.lang.UnsatisfiedLinkError: java.lang.UNIXProcess.init()V
      at java.lang.UNIXProcess.init(Native Method)
      at java.lang.UNIXProcess.&lt;clinit&gt;(UNIXProcess.java:295)
      at java.lang.ProcessImpl.start(ProcessImpl.java:130)
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
      at mycompany.PCtrlDsu.getDsuIP(PCtrlDsu.java:136)
      at mycompany.PCtrlDsu.main(PCtrlDsu.java:41)
  </code></pre>
  
  <p>I have also tried other ways to run it as well, resulting in the same error:</p>
  
  <h1>Running the process using exec</h1>
  
  <p>Here is one of the ways I've tried using exec to run it:</p>
  
  <pre><code>String[] cmd = {"/home/simulations/scripts/getDsuIp.sh"};
  Process p = Runtime.getRuntime().exec(cmd);
  InputStream in = p.getInputStream();
  BufferedReader br = new BufferedReader(new InputStreamReader(in));
  String result = br.readLine();
  p.waitFor();
  System.out.println ("exit: " + p.exitValue());
  p.destroy();
  </code></pre>
  
  <p>This fails on the second line when it tries to run the "exec" function.</p>
  
  <pre><code>Exception in thread "main" java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
  Caused by: java.lang.UnsatisfiedLinkError: java.lang.UNIXProcess.init()V
      at java.lang.UNIXProcess.init(Native Method)
      at java.lang.UNIXProcess.&lt;clinit&gt;(UNIXProcess.java:295)
      at java.lang.ProcessImpl.start(ProcessImpl.java:130)
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
      at java.lang.Runtime.exec(Runtime.java:617)
      at java.lang.Runtime.exec(Runtime.java:450)
      at java.lang.Runtime.exec(Runtime.java:347)
      at mycompany.PCtrlDsu.getDsuIP(PCtrlDsu.java:110)
      at mycompany.PCtrlDsu.main(PCtrlDsu.java:55)
  </code></pre>
  
  <h1>Try #2 with Process Builder</h1>
  
  <p>I tried implementing this solution:
  <a href="https://stackoverflow.com/questions/25647806/running-shell-script-from-external-directory-no-such-file-or-directory">Running Shell Script From External Directory: No such file or directory</a></p>
  
  <pre><code>        String script = "getDsuIp.sh";
          try {
              Process awk = new ProcessBuilder("/bin/bash", "/home/simulations/scripts/" + script).start();
              awk.waitFor();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
  </code></pre>
  
  <p>But I get the same error:</p>
  
  <pre><code>Exception in thread "main" java.lang.reflect.InvocationTargetException
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
  Caused by: java.lang.UnsatisfiedLinkError: java.lang.UNIXProcess.init()V
      at java.lang.UNIXProcess.init(Native Method)
      at java.lang.UNIXProcess.&lt;clinit&gt;(UNIXProcess.java:295)
      at java.lang.ProcessImpl.start(ProcessImpl.java:130)
      at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
      at mycompany.PCtrlDsu.getDsuIP(PCtrlDsu.java:143)
      at mycompany.PCtrlDsu.main(PCtrlDsu.java:41)
  </code></pre>
  
  <p><strong>Does anyone know what the "java.lang.UnsatisfiedLinkError: java.lang.UNIXProcess" error means?</strong></p>
  
  <p>Java Version:</p>
  
  <pre><code>java version "1.7.0_79"
  OpenJDK Runtime Environment (fedora-2.5.5.0.fc20-x86_64 u79-b14)
  OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
  </code></pre>