Hi i tried to execute the following command from java code in linux, ls > out.txt
here is my code
try
{
Process p=Runtime.getRuntime().exec("ls > out.txt");
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
System.out.println(line);
line=reader.readLine();
}
}
catch(IOException e1) {}
catch(InterruptedException e2) {}
System.out.println("Done");
I checked output file was not generated. However if I leave the output file part only run ls command it successfully executes without error and I can see the output.