Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6752813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:05:18+00:00 2026-05-26T13:05:18+00:00

I am trying to get command output from Linux box eg: tnsping and I

  • 0

I am trying to get command output from Linux box

eg: tnsping

and I want to preserve it’s newline characters.

Below is the code where I add command(s) to frows and pass it to a function for execution

def oracleCommand(csm,pluginOutputs)
{
HashMap<String,String> params = IntermediateResults.get("userparams")
Map env=AppContext.get(AppCtxProperties.environmentVariables)

def fClass = new GroovyClassLoader().parseClass( new File( 'plugins/infa9/Infa9CommandExecUtil.groovy' ) )
List<String> frows
frows=["tnsping $params.tns"]  //for the time being only one command is here

List<String> resultRows = fClass.newInstance().fetchCommandOutput( params, env, frows )

csm.oracleCommand(){
    oracle_input(frows[0]){}
    oracle_output(resultRows[0]){}
}
}

In the below code I am reading the result, splitting result based on newlines so all my newlines are gone

    public List<String> fetchCommandOutput( Map<String,String> params, Map env, List<String> rows )
  {

        List<String> outputRows = new ArrayList<String>()
        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
  }

update
How can i preserve my newlines or carriage returns, such that when the xml is opened with a xsl and when encountered <pre></pre> it should preserve its formatting?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:05:19+00:00Added an answer on May 26, 2026 at 1:05 pm

    If I get you right, You should use \r and \n:

    result.append(line+"\r\n");
    

    or, you can get the line separator from the system:

    result.append(line+System.getProperty("line.separator"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting output from my linux box running the ifconfig command. I do
I'm trying to get output value from DB via ADO.NET. There's a client code:
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
I am trying to log the output from cmd tree command using ant with
I'm trying to get output from a python multiprocessing Process displayed in a Tkinter
I'm brand new to Prolog. I am simply trying to get some output from
I'm trying to do some processing on the output from a psftp ls command.
I am trying to get output from a subprocess and then give commands to
I am trying to get certain output for svn command in XML format. Output
I'm trying to get a compile command (rake cucumber) to run with a specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.