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?

  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 <some-folder>") 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?


It seems that the bash command line proposed by PaĆ­lo does not work:

C:\cygwin\bin>bash -c ls -la
-la: ls: command not found

I am having trouble figuring out the technicalities.

This is my code:

p = Runtime.getRuntime().exec("C:\\cygwin\\bin\\bash.exe -c ls -la");
reader2 = new BufferedReader(new InputStreamReader(p.getInputStream()));
line = reader2.readLine();

line ends up having a null value.


I added this to my .bash_profile:

#BASH
export BASH_HOME=/cygdrive/c/cygwin
export PATH=$BASH_HOME/bin:$PATH

I added the following as well:

System Properties -> advanced -> Environment variables -> user variebales -> variable: BASH, value: c:\cygwin\bin

Still nothing...

However, if I execute this instead, it works!

p = Runtime.getRuntime().exec("c:\\cygwin\\bin\\ls -la ~/\"Eclipse_Workspace/RenameScript/files co
Edit
Report