I need to execute the following Change directories commands into the cmd prompt, but using java to execute them. the dir command works fine , but not the cd ones. I have to execute them in a single cmd windows
cd inputDir
dir
cd outputDir
inputDir and outputDir are directories from the windows.
Java Snippet:
ArrayList<String> dosCommands = new ArrayList<String>();
Process p;
for (int i=0;i< dosCommands.size();i++){
p=Runtime.getRuntime().exec("cmd.exe /c "+dosCommands.get(i));
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
System.out.println(line);
line=reader.readLine();
}
}
UPDATE
Changing the argument to cmd.exe /k instead of /c
p=Runtime.getRuntime().exec("cmd.exe /k "+dosCommands.get(i));
I had to remove the
p.waitFor();
method, because I was getting stucked in it. Doing so, know I do get stucked in the
line.reader.readLine();