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 6629589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:16:55+00:00 2026-05-25T22:16:55+00:00

I have a code which executes a command in Linux box ( ls –

  • 0

I have a code which executes a command in Linux box (ls - latr /home/ars | awk '{if(NR>1)print}') which gives me list of directories along with its information. How do I put it into some array or list so that depending on each line I can get filename, permissions etc from the (list or array)!!

Here is my code which prints an output at the bottom of my question
here cmd=ls - latr /home/ars | awk '{if(NR>1)print}'

function calling

HashMap<String,String> params = IntermediateResults.get("userparams")
    Map env=AppContext.get(AppCtxProperties.environmentVariables)
    def fClass = new GroovyClassLoader().parseClass( new File( 'plugins/infa9/Infa9CommandExecUtil.groovy' ) )
    String cmd="ls -latr "+rrs.get("linkpath")+" | awk '{if(NR>1)print}'"
    String res=fClass.newInstance().fetchInformation( params, env, cmd )

my function called

public String fetchInformation( Map<String,String> params, Map env, String cmd ) 
{
try
{
    Process proc = Runtime.getRuntime().exec(cmd);
    InputStream stdin = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(stdin);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ((line = br.readLine()) != null)
    {
        result.append(line);
        println "$line" // This output is given at the end
    }
    int exitVal = proc.waitFor();

} 
catch (IOException io) 
{
    io.printStackTrace();
}
catch (InterruptedException ie) 
{
    ie.printStackTrace();
}
//println("\n\n"+result)
return  result
 }

my output

/data/u01/app/oracle/10.2.0/db_1:
total 260
-rwxr-xr-x  1 oracle dba     0 Jun  7  2005 root.sh.old
drwxr-xr-x  4 oracle dba  4096 Jan 17  2007 xdk
drwxr-xr-x  4 oracle dba  4096 Jan 17  2007 uix
drwxr-xr-x  3 oracle dba  4096 Jan 17  2007 tg4tera
drwxr-xr-x  3 oracle dba  4096 Jan 17  2007 tg4sybs
drwxr-xr-x  3 oracle dba  4096 Jan 17  2007 tg4ingr
drwxr-xr-x  3 oracle dba  4096 Jan 17  2007 tg4ifmx

So how can I put the above output in some List so that on each line I can get permissions, hardlink,owner, group,filesize,month, date, time, year and finally filename?

Update

This is what I am trying to do, is there a better way may be by using maps?

 List<List<String>> frows = new ArrayList<List<String>>()
    while ((line = br.readLine()) != null)
    {
        List<String> fileList= new ArrayList<String>()
        result.append(line);
        String[] strs = line.split(" ")
        for(item in strs)
        {
            //print "$item "
            fileList.add(item)

        }

        frows.add(fileList)
    }

    for (List<String> l : frows) 
    {
      for (String s : l) {
        print "$s"
      }
      println ""
    }
  • 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-25T22:16:55+00:00Added an answer on May 25, 2026 at 10:16 pm

    Create a class say FileDetail with properties permissions, hardlink,owner, group,filesize,month, date, time, year and filename. Inside your method

    List<FileDetail> fileDetails = new ArrayList<FileDetail>();
    while ((line = br.readLine()) != null)
        {            
            FileDetail file = new FileDetail();
            println "$line" // This output is given at the end
            // parse - use space delimiter and String.split() API
            String[] strs = line.split(" ");
            // set values to "file"
            // add to list
            fileDetails .add(file);
        }
     return fileDetails;
    

    Using Map,

        List<Map<String, String>> files = new ArrayList<Map<String, String>>()
        while ((line = br.readLine()) != null) {
                Map<String, String> file = new Map<String, String>()       
                String[] strs = line.split(" ")        
                // Find the order of fields, but it is system dependent, may not work in futrue           
                file.add("PERMISSIONS", strs[0]); // and so on for next and you may need to trim map value 
                files.add(file);
                println "$line"
        } 
    return files;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code which needs to do something like this There is a list
I have written the java code below, which executes another java program named Newsworthy_RB.
I have this formula in a cell: =GetData(Channel_01,Chicago) Which executes this code: Public Function
Background: I have created a custom HttpHandler which executes a particular command based on
As part of my Java mapper I have a command executes some standalone code
I have a form with a few buttons which execute code when pressed like
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {
I have code which as been working against an older Active Directory server and
I already have code which lazy loads scripts on request. My issue now is
I have some code which collects points (consed integers) from a loop which looks

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.