Results 1 to 8 of 8
  1. #1
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default Script execution from java

    HI ,

    I am looking to execute the scripts from java, the scripts can be of any scripts like shell scripts, perl, python . Could someone help me on this

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,380
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by umapathy_sekar View Post
    HI ,

    I am looking to execute the scripts from java, the scripts can be of any scripts like shell scripts, perl, python . Could someone help me on this
    Look at the API documentation (and read it) for the Runtime.exec( ... ) methods.

    kind regards,

    Jos

  3. #3
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default Clarifications

    I am aware of runtime.exec() but just want to know if it holds good for all types of scripts like shell , perl , python etc. Now i dont have linux environment so first looking for code

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,380
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by umapathy_sekar View Post
    I am aware of runtime.exec() but just want to know if it holds good for all types of scripts like shell , perl , python etc. Now i dont have linux environment so first looking for code
    If you're running MS Windows you either have to set the proper file associations or you have to find the correct interpreter given the extension of your script file.

    kind regards,

    Jos

  5. #5
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default Facing an issue in executing script.. could someone help

    If the script exists in the same location as the java file. I am able to execute the script through java but if the script exists in different location i am not able to execute .. Could someone help

    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("./hello.sh");

    How to specify if the script exists in different location in unix machine ?

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,380
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by umapathy_sekar View Post
    If the script exists in the same location as the java file. I am able to execute the script through java but if the script exists in different location i am not able to execute .. Could someone help

    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("./hello.sh");

    How to specify if the script exists in different location in unix machine ?
    You either have to set your 'path' variable before you start your Java program or you have to supply the absolute path to where your script is stored.

    kind regards,

    Jos

  7. #7
    Join Date
    Sep 2010
    Posts
    16
    Rep Power
    0

    Default Which path variable ?

    Hi ,

    I am sorry am quite new to this unix environment. Could you please elaborate more ?. I used to run java program only in eclipse so not sure of the variables to be set.

    Could you provide me the exact thing. Thanks for the reply.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,380
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by umapathy_sekar View Post
    Hi ,

    I am sorry am quite new to this unix environment. Could you please elaborate more ?. I used to run java program only in eclipse so not sure of the variables to be set.

    Could you provide me the exact thing. Thanks for the reply.
    If your script is stored here /path/to/your/script you either have to add the directory /path/to/your to your 'path' environment variable or you have to specify the complete path /path/to/your/script to one of the exec( ... ) methods. The OS needs a way to find your script.

    kind regards,

    Jos

Similar Threads

  1. Replies: 2
    Last Post: 06-01-2010, 02:58 AM
  2. Java script
    By kirtichopra2003 in forum Advanced Java
    Replies: 1
    Last Post: 12-04-2009, 07:55 PM
  3. java script
    By satti in forum Web Frameworks
    Replies: 0
    Last Post: 06-09-2009, 08:53 AM
  4. Need help in java program execution...
    By sachinmittal in forum New To Java
    Replies: 6
    Last Post: 10-10-2008, 02:37 PM
  5. Replies: 25
    Last Post: 06-28-2008, 05:08 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
  •