import java.io.*;
class PT
{
  public static void main(String[] args) throws IOException
  {
  String filename="out.txt";
  if(args.length>0){
  filename=args[0];
  }
  String command="cmd /C dir";
  Runtime r=Runtime.getRuntime();
  Process p=r.exec(command);
  BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream()));
  PrintStream ps=new PrintStream(new FileOutputStream(filename));
  String inline;
  while(null!=(inline=br.readLine())){
  ps.println(inline);
  }
  System.out.println("a command result has been readed to a file "+filename);
  }
}