Results 1 to 2 of 2
  1. #1
    roise_r is offline Member
    Join Date
    May 2011
    Rep Power

    Default Thread: 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?

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

Similar Threads

  1. Running commands in cygwin(aspell) through java
    By nikhidas in forum Advanced Java
    Replies: 0
    Last Post: 06-22-2011, 08:24 PM
  2. Execute Cygwin command from Java app
    By ZebraIzToronto in forum Advanced Java
    Replies: 1
    Last Post: 01-21-2011, 05:51 AM
  3. Run Unix commands from Java
    By yahyaaa in forum New To Java
    Replies: 13
    Last Post: 06-17-2010, 11:50 PM
  4. Need Help to Execute the commands from Java Program
    By Anjaneyulu in forum Advanced Java
    Replies: 7
    Last Post: 02-24-2010, 02:35 PM
  5. how to run java app on windows in a cron like on unix
    By rockie12 in forum Advanced Java
    Replies: 7
    Last Post: 05-23-2008, 01:39 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts