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 ""
}
Create a class say
FileDetailwith properties permissions, hardlink,owner, group,filesize,month, date, time, year and filename. Inside your methodUsing Map,