Current Position:Home > Calling the system

Calling the system

Update:11-30Source: network consolidation
Advertisement
How can I call the linux's system example (ls) with java.

The Best Answer

Advertisement
public class CallSystem
public void callProgram(String programnarguments)
  String line = null;
  Process p = System.getRuntime.exec(programnarguments);
  BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
  while ((line = br.readLine()) != null)
    System.out.println(line);
} // callProgram
...snip...
public CallSystem()
  callProgram("ls");
  callProgram("ls -la");
} // CallSystem
} // CallSystem