title: passthru() centos LD_LIBRARY_PATH
body: <p>I am having troubles with the passthru() command when executing Java programs. More specifically with setting the LD_LIBRARY_PATH using passthru.</p>
  
  <p>I tried:</p>
  
  <blockquote>
    <ul>
    <li>setting the .so file path directly like this:</li>
    </ul>
    
    <p>passthru("java
    -Djava.library.path='.:/path/to/directory/of/.so/object' " HelloWorld);</p>
    
    <ul>
    <li><p>writing a shell script which sets the LD_LIBRARY_PATH,then executing the shell script using passthru.</p></li>
    <li><p>acessing the /etc/profile file and adding the "export LD_LIBRARY_PATH..." line in the document.</p></li>
    </ul>
  </blockquote>
  
  <p>These are just few solutions I found online which I thought would work, but none worked. I believed the problems come from concatenation stuff in the passthru command as I saw on several sites stuff like that:</p>
  
  <blockquote>
    <p>$command = 'export LD_LIBRARY_PATH="' . $path_to_library_dir .'"; ' .
    $path_to_binary; passthru($command);</p>
  </blockquote>
  
  <p>which I also tried.But I dont know what am doing wrong.</p>
  
  <p>Please, can anyone help?</p>
  
  <p>Thank you!</p>
  
  <hr>
  
  <blockquote>
    <p><em><strong>EDIT 1</em></strong></p>
  </blockquote>
  
  <p>Using @lexmihaylov suggestion:</p>
  
  <p>Hi,
  Thank you for replying.
  Actually I get an "java.lang.UnsatisfiedLinkError:/usr/lib/libjpcap.so". So that's why I am trying to set up the LD_LIBRARY_PATH to my .so object.</p>
  
  <p>From your answer I tried:</p>
  
  <pre><code>$Path_to_library_dir = '/usr/lib64/jpcap';
  $Path_to_binary = '/usr/lib64/jpcap/libjpcap.so'; 
  $command = 'LD_LIBRARY_PATH="' . $Path_to_library_dir .'" '.$Path_to_binary; 
  </code></pre>
  
  <blockquote>
    <p><code>passthru($command);</code></p>
  </blockquote>
  
  <pre><code>$java_execution = "java myjavaprogram 2&gt;&amp;1"; 
  </code></pre>
  
  <blockquote>
  <pre><code>echo passthru($java_execution,$output);
      echo $output;
  </code></pre>
  </blockquote>
  
  <p>I still get the same java.lang.UnsatisfiedLinkError. But if I set the LD_LIBRARY_PATH directly in my terminal, my java program works fine when executed via terminal.</p>
  
  <p>Thank you for helping!</p>