Reputation: 51
How to execute Windows or Linux commands from a Java application?
I want to run dir
command from Java application without a command prompt.
How can this be done?
Upvotes: 1
Views: 226
Reputation: 27614
Just a note, dir
is not an executable as such, but a command in the Windows command interpreter. To run dir
, you would do Runtime.getRuntime().exec("cmd /C dir");
Upvotes: 0
Reputation: 6054
probably you may need to read output of executed app as well, if you need that
Process p = Runtime.getRuntime().exec("...");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = br.readLine()) != null)
System.out.println(line);
Upvotes: 0
Reputation: 4883
well .. you could do it with
Runtime.getRuntime().exec("...")
but you really don't want to ..
if you want to get a list of files in a directory use the File api! something like file.listFiles()
Upvotes: 7