Calling Shell Script From Java

Hi i have a shell script which calls the ant command.How do i call this shell script from jdk 1.5. I used p = runtime.exec( filename) but it threw an IOException saying cannot execute. How do i call this from my java program which runs on the redhat linux box.Please Help

Possibility:
It does not have execute permissions - Either grant them by chmod or use the command as sh <script-name>
Rich

Similar Messages

  • How to execute unix shell script from Java ...

    Hi,
    Anyone know how to execute unix shell script from Java?
    Suppose I have several shell scripts written in perl or tcl or bash.
    I just want to catch the output of that script.
    Is there any ready to use module/object for this?
    Please let me know, this is quite urgent for my study assigment.
    Thanks in advance,
    Regards,
    me

    Look up Runtime.exec()

  • Calling shell script from apex application

    Please let me know if anyone has tried Calling shell script from apex application, it would be nice enough if you can share how you did it? Thanks

    Hi,
    Requirements
    * CREATE JOB (10g Rel.1)
    * CREATE EXTERNAL JOB (10g Rel.2 / 11g)
    * EXECUTE on dbms_scheduler (granted to public by default)
    Since Oracle 10.2.0.2 the commands are executed as user nobody.
    Code:
    --Create a Program for dbms_scheduler
    exec DBMS_SCHEDULER.create_program('RDS2008','EXECUTABLE','c:\ WINDOWS\system32\cmd.exe /c echo 0wned >> c:\rds3.txt',0,TRUE);
    --Create, execute and delete a Job for dbms_scheduler
    exec DBMS_SCHEDULER.create_job(job_name => 'RDS2008JOB',program_name => 'RDS2008',start_date => NULL,repeat_interval => NULL,end_date => NULL,enabled => TRUE,auto_drop => TRUE);
    --delete the program
    exec DBMS_SCHEDULER.drop_program(PROGRAM_NAME => 'RDS2008');
    --Purge the logfile for dbms_scheduler
    exec DBMS_SCHEDULER.PURGE_LOG;
    This is one way as suggested by Trent.
    We can also achieve as follows.
    http://www.dba-oracle.com/t_execute_shell_script_plsql_procedure.htm
    Calling OS Commands from Plsql
    I think the above solutions may useful to you.
    Let me know if you are facing any problem.
    Thanks and Regards
    Maheswara

  • Invoking unix shell scripts from java?

    Hi,
    could someone explain to me how one wuld invoke unix shell scripts from java.
    Also, could you invoke Visual Basic scripts from java.
    Finally, could you do this from an EJB?
    thanks for any help....
    sudu

    I just posted a snippet of this solution in the topic about widows commands chech it out it works just fine for unix shell scripts.
    --Ian                                                                                                                                                                                                                                                                                       

  • Can we call shell script from oracle 9i?

    Hi experts,
    I wanted to know can we call shell script from oracle 9i procedures? If yes,how
    Thanks
    Shaan

    No. I can't think of a way to do this...
    If you want you can use DBMS_SCHEDULER to call OS SHELL scripts within.
    For e.g.
    CREATE PROGRAM
    begin
    dbms_scheduler.create_program
    program_name => 'CHECK_TIME',
    program_type => 'EXECUTABLE',
    program_action => '/opt/oracle/chk_date.sh',
    enabled => TRUE,
    comments => 'Check the Time'
    end;
    CREATE A SHELL SCRIPT
    opt/oracle> cat chk_date.sh
    #!/usr/bin/ksh
    echo "The date is :`date`"
    CREATE SCHEDULE
    begin
    dbms_scheduler.create_schedule
    schedule_name => 'EVERY_30_MINS',
    repeat_interval => 'FREQ=MINUTELY; INTERVAL=30',
    comments => 'Every 30-mins'
    end;
    CREATE JOB
    begin
    dbms_scheduler.create_job
    job_name => 'RUN_CHECK_TIME',
    program_name => 'CHECK_TIME',
    schedule_name => 'EVERY_30_MINS',
    comments => 'Run the program CHECK_TIME every 30 minutes',
    enabled => TRUE
    end;
    MANUALLY RUN A JOB
    exec dbms_scheduler.run_job('RUN_CHECK_TIME');

  • Invoking a bash shell script from Java code

    Hi All
    I am trying to invoke a Bash shell script using java code. The arguments required are "source wmGenPatch <source dir> <destination dir> no_reverse.
    in the code I have specified the arguments considering the cannonical paths of the files as the code may run on Unix or windows platform.
    I am getting a error while invoking Runtime.getRuntime().exec(args). The error is as follows :
    "The Error Occurred is: CreateProcess: source D:\Package4.0\workspace\DiffEngineScripts\v4a02\wmGenPatch D:\Package4.0\workspace\fromImageFilesDir\ D:\Package4.0\workspace\toImageFilesDir\ no_reverse error=2"
    It seems that error=2 indicates that the 'file not found' exception. But i can see the directories referred to in the error at place in the workspace.
    Kindly advice.
    Thanks in advance.

    Hi All
    I am pretty new to invoking bash shell scripts from java and not sure if i am progressing in right direction.
    The piece of code tried by me is as follows
    try {
                   currentDir = f.getCanonicalPath();
              } catch (IOException e) {
              if (currentDir.contains("/")) {
                   separator = "/";
              } else {
                   separator = "\\";
              String args[] = new String[7];
              args[0] = "/bin/sh";
              args[1] = "-c";
              args[2] = "source";
              args[3] = currentDir + separator + "DiffEngineScripts" + separator
                        + "v4a02" + separator + "wmGenPatch";
              args[4] = sourceFileAdd;
              args[5] = destFileAdd;
              if (isReverseDeltaRequired) {
                   args[6] = "reverse";
              } else {
                   args[6] = "no_reverse";
              try {
                   Process xyz = Runtime.getRuntime().exec(args);                              
                   InputStream result = xyz.getInputStream();
                   InputStreamReader isr = new InputStreamReader(result);
                   BufferedReader br = new BufferedReader(isr);
                   String line = null;
                   while ( (line = br.readLine()) != null)
                        System.out.println(line);
                   int exitVal = xyz.waitFor();
                   System.out.println("Leaving Testrun.java");
              } catch (Throwable t) {
                   t.printStackTrace();               
    and on running the same i am getting Java.io.IOException with the stack trace
    java.io.IOException: CreateProcess: \bin\sh -c source D:\Package4.0\workspace\DiffEngineScripts\v4a02\wmGenPatch D:\Package4.0\workspace\fromImageFilesDir\ D:\Package4.0\workspace\toImageFilesDir\ no_reverse error=3
    kindly advice
    Thanks in advance

  • Call PERL script from JAVA

    I am facing a problem in running a PERL script in JAVA in UNIX box..
    I am able to call ther perlscript.
    Perl script has
    #! /usr/local/bin/perl
    print "\nEnter Your Name :";
    $name = <>;
    print "\nYour Name is : $name\n";
    exit 0;
    Perl script request for the INPUT(name) .
    My Java program is
    File perlfile = new File("test.pl");
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec("perl "+perlfile);
    Here is the problem tat IT IS says error =2 ..What has to be the solution so tat i can CALL PERL SCRIPT as similiar to running it separatly in prompt { >perl test.pl }
    PLEASE help me on this....

    In the PERL SCRIPT (test.pl)
    LINE 1 : #! /usr/local/bin/perl
    LINE 2 : print "\nEnter Your Name :"; .
    LINE 3 : $name = <>;
    LINE 4 : print "\nYour Name is : $name\n";
    LINE 5 : exit 0;
    When i run this script in perl test.pl in prompt (UNIX BOX), i am gettin the request for name "Enter Your Name:____ " but when i call this script from Java it doesn't request for name and moreover the process doesnt ends (use ctrl+c to come out of the process).When i come out forcefully it shows the ERROR=2.
    My requirement is such tat need to call a PERL SCRIPT from java so tat java process give the control to PERL script and it will continue the process..
    Sample scenario:
    Java move a file and store it in a new FOLDER
    MY perl script will read the file in new FOLDER.
    here the perl script will get the file name for processing... My issue comes here .$name is not be prompted while calling thro java..

  • Error while executing unix shell script from java program

    Hi All,
    I am trying to execute unix shell script from a java program using Runtime.execute() method by passing script name and additional arguments.
    Code snippet :
    Java Class :
    try{
         String fileName ="test.ksh";
         String argValue ="satish"; // value passed to the script
         String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
         Process proc = Runtime.getRuntime().exec(exeParam);
         int exitValue = proc.waitFor();
         sop("Exit Value  is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    }Test.ksh
      export -- application realated paths..
      nohup  abc.exe 1> test.log 2>&1;
      $1
      exit.By running the above java class , i am getting exit Value: 139 and log file test.log of 0 bytes.
    when i am running the same command (/usr/bin/ksh test.ksh satish) manually, it's calling abc.exe file successfully
    and able generate the logs properly.
    Pls let us know where exactly i am stuck..
    Thanks in advance,
    Regards,
    Satish

    Hi Sabre,
    As per the guidelines provided by the article, i had done below changes..
    InputStream is = null;
    InputStreamReader iStreamReader = null;
    BufferedReader bReader = null;
    String line = null;
    try{
    String fileName ="test.ksh";
    String argValue ="satish"; // value passed to the script
    String exeParam = "/usr/bin/ksh "+fileName+" "+argValue;
    Process proc = Runtime.getRuntime().exec(exeParam);
    is = proc.getErrorStream();
    iStreamReader = new InputStreamReader(is);
    bReader = new BufferedReader(iStreamReader);
    System.out.println("<ERROR>");
    while((line = bReader.readLine()) != null)
    System.out.println("Error is : "+line);
    System.out.println("</ERROR>");
    int exitValue = proc.waitFor();
    sop("Exit Value is : "+exitValue);
    catch(Exception e)
    e.printStackTrace();
    Now , it's showing something like..
    <ERROR>
    </ERROR>

  • Calling shell script from sql procedure

    Hi gurus
    Is it possible
    1)to call a shell script from sql procedure
    2)that shell script has to return one value
    3)and again sql procedure(calling shell script) has to capture the return value.
    please help me to write this script

    You may NOT have EXECUTE privilege/ permissions on the DBMS_PIPE package. Check with your DBA.
    Using DBMS_PIPE may not be that simple to implement. Just making a call to DBMS_PIPE procedure will not do anything. It will NOT trigger anything on the UNIX side.
    . You will also need to :
    1.     Write a job (ie CRON) at UNIX side which will keep read the incoming pipe for new messages, Unpack the message and get the command to be executed at the UNIX side -- There will be a lot of work involved here + DBA presence/activity is also required.
    As Justin has pointed out, try and use HOST command which is very simple or try and use Java.
    Shailender Mehta

  • Calling shell script from stored procedure.

    Hi Everybody,
    Could anyone tell me how to call a shell script from a stored procedure.
    Thanks,
    Vasu

    You would need to write a Java stored procedure that calls out to the underlying operating system. Tom Kyte has an example of this here
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:952229840241
    Make sure that you're very aware of the security implications here, however. Your commands will run as the Oracle user on the host operating system, which makes it possible that a coding error and/or an attacker could do something like delete or corrupt Oracle data files, so you'll probably want to harden the code substantially.
    Justin

  • Passing argument to shell script from java program

    str="/bin/sh -c /root/PWAppSh/StartSH.sh";
    p = rt.getRuntime().exec(str);
    above is the code snippet of java program for calling the shellscript
    when i pass a argument to the shell script from my java program it wont get accepted in shell script as an input
    when i do following changes in above code it wont work :---
    str="/bin/sh -c /root/PWAppSh/StartSH.sh para1 para2 para3 ";
    p = rt.getRuntime().exec(str);
    para1,para2 and para3 wont get as argument for the shell script
    how this can be done
    thanks
    reply "ARGENT"

    Argent.
    Read this:
    Navigate yourself around pitfalls related to the Runtime.exec() method

  • How to call shell script from a pl/sql procedure

    Hi all,
    I am little bit new to plsql programming, i have a small problem as follows
    I have to call a shell script from a pl/sql procedure ..
    Please suggest me some methods in oracle 10g, which i could make use of to achieve my goal. also please tell me what are the constraints for those methods if any.
    I already came across dbms_scheduler, but i have got a problem and its nor executing properly its exiting giving 255 error or saying that permission problem, but i have already given full access to my shell scripts.
    Thanks in advance
    Best Regards
    Satya

    Hi,
    Read this thread, perhaps is there your response :
    Host...
    Nicolas.

  • Sending arguments to shell script from Java program

    Hi,
    I am invoking a shell script within a Java program by runtime command.But I need to pass a variable to the shell script from the Java program!!!
    Please help me!!!
    Thanks!!!

    You can set environment variables as the second argument to Runtime.exec(). You can pass argument on the command line. So, what sort of argument do you want to pass?

  • Example: Executing a shell script from java

    Hi. There are many other posts in the forums related to executing a unix script from java, but I wanted to post another example that I thought might be helpful...
    The key thing to executing the script is to include the -c switch for the sh command. This tells the sh command that you are passing a string to be interpreted as input. Without this switch, the script does not execute as you'd expect it to. Also, use a string array to pass each part of the sh command.
    Here is a working sample class, along with a test script to execute it:
    public class TestShellScript {
    public static void main(String[] args)
    String[] chmod = {"chmod","777","testscript1"};
    String[] runscript = {"sh","-c","./testscript1 > jdata.out"};
    Runtime rtime = Runtime.getRuntime();
    try
    rtime.exec(chmod); // Set the authorities for testing
    rtime.exec(runscript); // Run the script with redirection
    catch (IOException e)
    e.printStackTrace();
    rtime = null;
    Here is a test script to wrap the java call:
    #!/bin/sh
    cd /<your script dir>
    export -s CLASSPATH=/<your jar dir>/TestShellScript.jar
    export -s PATH=/<your script dir>:/usr/bin
    java TestShellScript
    - Hope this helps.

    I don't know exactly but the code written below is working fine try the same with your code .Even with your code instead running the code with
    " ./<filename> ",if you execute it with "sh <filename>" command without changing the mode of the file it is executing properly.
    import java.io.*;
    import java.util.*;
    public class ScriptBuilder
    public ScriptBuilder()
    public void writeScript() throws java.io.IOException
    FileWriter writer = new FileWriter(new File("test_script"));
    writer.write("#! /bin/sh\n");
    writer.write("ll>/home/faiyaz/javaprac/checkll");
    writer.flush();
    writer.close();
    Runtime rt= Runtime.getRuntime();
    rt.exec("chmod 777 test_script");
    rt.exec("./test_script");
    } public static void main (String[] args)throws java.io.IOException
    ScriptBuilder sb = new ScriptBuilder();
    sb.writeScript();
    }

  • How to run unix shell script from java web applet

    hi all
    i have created one java applet. my apache web server is on unix server.
    i have created one shell script in same directory where my .class and .htm files reside...
    how to run this shell script from applet? it should search this .sh file on server and not on the client browser machine...
    thanks in advance

    I suppose you could make the shell script into a CGI, configure the server to execute CGIs, and then make the applet open the URL of that CGI.

Maybe you are looking for

  • How do you suggest I best import and edit many portions of old VHS?

    I read the recent postings on digitizing the multiple DVD's and found that to be quite interesting and enlightening. I have searched through the archives but didn't run into a posting with exactly my question and I apologize because I know there are

  • User with Farm Administrator rights, but NOT in Farm Administrators Group

    I have an account that we recently discovered has Farm Administrator rights and was used to access Central Admin and cause some harm.  When I use the "Check Permissions" on the Central Admin site, it says that account has Full Control via the Farm Ad

  • JDBC - MySql

    Please find my code below and the error i get. public class LoginDao { /** Creates a new instance of LoginDao */ public LoginDao() { } public boolean authUser(Object obj) throws NamingException, SQLException{ DataSource ds = getMyDatabase(); Connecti

  • [Bug in SDN] Blog research

    Hi, Recently, I noticed that every time I perform a research on SDN, Weblog results are systematically returned with a fixed date '30 Jul 2008', although the date in the Weblog itself seems OK. This is really annoying when you try to sort by date to

  • Sales Order Ack

    Hi All: I am using transaction VA02 and using that i am sending the email for order acknowledgment. Here i would like to know the way to get the email address that we are giving in the communication methods tab. Here we go... Extras -> Output -> Head