Skip to main content
2 of 3
added 184 characters in body
AJJ
  • 3.6k
  • 7
  • 48
  • 78

This one works... using && operator you can add one or commands to be executed in same command prompt

try {
    Process p = Runtime
                    .getRuntime()
                    .exec("cmd /c start cmd.exe /K \"dir && ping localhost && echo end\"");
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

Consider the solution in here also

Update from the questioner: Solution to execute commands in cygwin

getRuntime().exec("cmd /c start C:/cygwin64/bin/bash.exe --login -c \"ls ; whoami ; exec bash\"");
AJJ
  • 3.6k
  • 7
  • 48
  • 78