title: keeping the newline and carriage return characters in java (groovy)
body: <p>I am trying to get command output from Linux box</p>
  
  <p>eg: <code>tnsping</code></p>
  
  <p>and I want to preserve it's newline characters.</p>
  
  <p>Below is the code where I add command(s) to <code>frows</code> and pass it to a function for execution</p>
  
  <pre><code>def oracleCommand(csm,pluginOutputs)
  {
  HashMap&lt;String,String&gt; params = IntermediateResults.get("userparams")
  Map env=AppContext.get(AppCtxProperties.environmentVariables)
  
  def fClass = new GroovyClassLoader().parseClass( new File( 'plugins/infa9/Infa9CommandExecUtil.groovy' ) )
  List&lt;String&gt; frows
  frows=["tnsping $params.tns"]  //for the time being only one command is here
  
  List&lt;String&gt; resultRows = fClass.newInstance().fetchCommandOutput( params, env, frows )
  
  csm.oracleCommand(){
      oracle_input(frows[0]){}
      oracle_output(resultRows[0]){}
  }
  }
  </code></pre>
  
  <p>In the below code I am reading the result, splitting result based on newlines so all my newlines are gone</p>
  
  <pre><code>    public List&lt;String&gt; fetchCommandOutput( Map&lt;String,String&gt; params, Map env, List&lt;String&gt; rows )
    {
  
          List&lt;String&gt; outputRows = new ArrayList&lt;String&gt;()
          try
          {
              for(item in rows)
              {
                  String temp=item.toString()
  
                  Process proc = Runtime.getRuntime().exec(temp);
                  InputStream stdin = proc.getInputStream();
                  InputStreamReader isr = new InputStreamReader(stdin);
                  BufferedReader br = new BufferedReader(isr);
                  String line = null;
  
                  result = new StringBuffer()
                  line=null
  
  
                  while ((line = br.readLine()) != null)
                  {
                      result.append(line+" #10#13 ")  //Here i am trying to add the newline again, but it does not reflect in the generated xml. it just come as plain text
                  }
                  String tRes=result
                  tRes=tRes.trim()
  
                  outputRows.add(tRes)
                  int exitVal = proc.waitFor();
  
              }
          }
          catch (IOException io)
          {
              io.printStackTrace();
          }
          catch (InterruptedException ie)
          {
              ie.printStackTrace();
          }
  
      return  outputRows
    }
  </code></pre>
  
  <p><strong>update</strong>
  How can i preserve my newlines or carriage returns, such that when the xml is opened with a xsl and when encountered <code>&lt;pre&gt;&lt;/pre&gt;</code> it should preserve its formatting?</p>