The /F
flag for CMD
is for file completion. Its probably safe to assume that you want the /C
flag to carry out the command. Without the /C
flag, the cmd.exe
will run interactively, looking for input, and your program will block indefinitely on waitFor
. Replace:
new ProcessBuilder("cmd.exe", "/f", "dir");
with
new ProcessBuilder("cmd.exe", "/c", "dir");