How to execute unix commands through Windows/cygwin using Java
I am trying to accomplish two things:
1. I am running cygwin on Windows7 to execute my unix shell commands and I need to automate the process by writing a Java app. I already know how to use the windows shell through Java using the 'Process class' and 'Runtime.getRuntime().exec(cmd /c dir)'. I need to be able to do the same with unix commands: i.e.: 'ls -la' and so forth. What should I look into ?
I have tried running 'Runtime.getRuntime().exec("C:\\cygwin\\bin
mintty.exe -e ls -la")' or 'Runtime.getRuntime().exec("C:\\cygwin\\bin
bash.exe -c ls -la");', but for some reason, both mintty and bash end up not recognizing basic commands like the 'ls' when they are called this way !?
2. Is there a way to remember a shell's state? explanation: when I use: 'Runtime.getRuntime().exec(cmd /c dir)' I always get a listing of my home directory. if I do 'Runtime.getRuntime().exec(cmd /c cd )' and then do 'Runtime.getRuntime().exec(cmd /c dir)' again, I will still get the listing of my home folder. Is there a way to tell the process to remember its state, like a regular shell would?