title: Attempting to return the output of a Unix command as a string in Java... not getting expected results
body: <p>I'm trying to create a little program in Java which will allow me to access a remote Unix server, run some commands and then display the output of those commands in the IDE.</p>
  <p>I've been smashing together bits of code and trying to learn how it works as I go along, which probably isn't ideal!</p>
  <p>Currently, I'm able to run the commands from the console and I'm able to see the results on the server, but I've been unable to send the output back to the console. Whenever I try to send them back as a string, I'm getting something along the lines of java.lang.UNIXProcess$ProcessPipeInputStream@9x57d1ad instead of the usual output that I'm seeing on the server. I'm sure there's something obvious I'm doing wrong, but I'm a beginner and despite spending hours searching I've not been able to find a solution yet. I'd really appreciate some help. Thanks!</p>
  <p>RUNNING ON SERVER:</p>
  <pre><code>public static void main(String[] args) {
      try {
          ServerSocket serverSocket = new ServerSocket(portNumber);
          Socket clientSocket = serverSocket.accept();
          PrintWriter out =
                  new PrintWriter(clientSocket.getOutputStream(), true);
          BufferedReader in = new BufferedReader(
                  new InputStreamReader(clientSocket.getInputStream()));
  
          while ((inputLine = in.readLine()) != null) {
  
              out.println(inputLine);
  
              if (inputLine.equals(&quot;storage&quot;)) {
                  runStorage();
                  printResults(runStorage()); }
  
       catch (Exception e) {
  
          e.printStackTrace();
  
      }
  
  public static Process runStorage() throws IOException {
  
      ProcessBuilder processBuilder = new ProcessBuilder();
      processBuilder.command(&quot;df&quot;, &quot;-h&quot;);
  
      Process process = processBuilder.start();
      printResults(process);
  
      return process;
  
  }
  
  public static String printResults(Process process) throws IOException {
      BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
      String line = &quot;&quot;;
      while ((line = reader.readLine()) != null) {
          System.out.println(line);
      }
      return line;  }
  </code></pre>
  <p>CLIENT:</p>
  <pre><code>        public class ClientInitiator {
  
              public static void main(String[] args) throws IOException, InterruptedException {
  
                  String hostName = &quot;myHostNameGoesHere&quot;;
                  Socket echoSocket = new Socket(hostName, portNumber);
                  PrintWriter out =
                          new PrintWriter(echoSocket.getOutputStream(), true);
                  BufferedReader in =
                          new BufferedReader(
                                  new InputStreamReader(echoSocket.getInputStream()));
                  BufferedReader stdIn =
                          new BufferedReader(
                                  new InputStreamReader(System.in));
  
  
                  {
                      String userInput;
  
                      while (!(userInput = stdIn.readLine()).equals(&quot;&quot;)) {
                          out.println(userInput);
                          if (userInput.equals(&quot;storage&quot;)) {
                              String serverResponse = in.readLine();
                              System.out.println(serverResponse);}
  </code></pre>