Results 1 to 5 of 5
  1. #1
    nenadm is offline Member
    Join Date
    Nov 2008
    Posts
    19
    Rep Power
    0

    Default Run program from Java

    Hi all,

    I need to run Cygwin (program which executes shell scripts on Windows) from Java,
    and run some script with Cygwin. Is it possible with Runtime.exec() run Cygwin and
    pass them some script to run?

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    Yes, just read.

    Do you want to lauch Cygwin as a separate process?
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    nenadm is offline Member
    Join Date
    Nov 2008
    Posts
    19
    Rep Power
    0

    Default

    Well i want Java application to wait until script do the job.
    When script is finished, my application need to process text file
    which is result of that script.
    I am interested is it possible to find out when this script (not Cygwin)
    is finished and after that close Cygwin program?

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default runtime asd process

    Not sure if this will answer your question about the running a script, but you would have to use the exec() method from the runtime class and the waitFor() method from the process class
    Runtime (Java Platform SE 6)
    Process (Java Platform SE 6)
    Example:
    Process: waitFor() : Process**java.lang**Java by API

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    jacob6900 is offline Member
    Join Date
    Nov 2008
    Posts
    5
    Rep Power
    0

    Default

    The following lets you execute a Cygwin command directly, in this instance the 'cat' command. It also waits for it to complete, after which you can send another command.
    -----
    Process runCommand1;
    String setCommand1 = "cmd /c cat ";

    Runtime run = Runtime.getRuntime();
    int exitValue = 1;

    try
    {
    Process proc = run.exec(setCommand1);
    exitValue = proc.waitFor();
    ...other stuff
    {
    except () {} ....etc
    -----

    The trick is to include the functions you need to use (cat.exe, sort.exe, etc) and cygwin1.dll in the main path of your application. The way I did it was to create a batch file that had the 'cat' command in it, and placed it in a temp folder along with the cygwin1.dll. Depending on which function you are trying to call, it will tell you which other dlls are required. For me cygintl-8.dll and cygiconv-2.dll did the trick. If you already have Cygwin installed the needed folders should already be on the path.

Similar Threads

  1. Java Program
    By icedragon770 in forum Java Applets
    Replies: 26
    Last Post: 10-12-2008, 01:24 AM
  2. need help with java program
    By pjr5043 in forum New To Java
    Replies: 2
    Last Post: 09-13-2008, 01:53 AM
  3. Java Program
    By littleBean in forum New To Java
    Replies: 7
    Last Post: 07-22-2008, 12:07 AM
  4. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

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