title: Java to securely execute a shell command
body: <p>What would be a good solution to ensure information security and integrity in the following scenario:</p>
  
  <p><img src="https://i.stack.imgur.com/Wz01z.png" alt="Figure 1"></p>
  
  <p>A Java application needs to do some initial work, then pass credentials (for example, a username and a password) to a shell command which will do some processing (possibly make requests over https, amongst other operations) and then return a private token to the Java application.<br>
  Let's assume for this discussion that the functionality of the shell command cannot be replicated in Java without reasonable effort and most of it is closed-source.  </p>
  
  <p>What would be a good manner to ensure neither the credentials nor the token can easily be hijacked by a third party?<br>
  Assume, that the IO can be customized as necessary in both the Java application and the shell command.</p>
  
  <hr>
  
  <p><sup>Icons from <a href="http://www.iconarchive.com/artist/saki.html" rel="nofollow noreferrer">Saki</a> &amp; <a href="http://www.iconarchive.com/artist/untergunter.html" rel="nofollow noreferrer">Untergunter</a></sup></p>