I\'m developing a Java application that will be run on a Windows computer occasionally. At some point I need to run a Cygwin prompt and performs some commands in it.
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\"");
If you do not need to show a console on the screen, that is easy. You have some simple steps to follow :
Process
via `Process cmd = new ProcessBuilder("cmd.exe").start();cmd.getOutputStream()
cmd.getInputStream()
and/or cmd.getErrorStream()
cmd.getOutputStream()
, and if necessary kill the process by cmd.destroy()
Optionnaly, you can have output and error stream to be merged :
Process cmd = new ProcessBuilder("cmd.exe").redirectErrorStream(true).start();
then you simply ignore cmd.getErrorStream()
and only read from cmd.getInputStream()
Not quite sure , but if i properly understand your problem , try : for windows at java conifguration panel, there should be un-ticked the show console button.