Run Perl script in my Java program

Some say that the following statement can run Perl script in Java program:
Runtime.getRuntime().exec("C:\\runPerl.pl");
But when I run it, it'll throw IOException:
java.io.IOException: CreateProcess: C:\runPerl.pl error=193
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:63)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at java.lang.Runtime.exec(Runtime.java:428)
at java.lang.Runtime.exec(Runtime.java:364)
at java.lang.Runtime.exec(Runtime.java:326)
at test.runPerl.main(runPerl.java:16)
Exception in thread "main"
Where is the problem? In fact, I do have a Perl script named "runPerl.pl" in my C:/ directory. Why can't it be run?

Please don't crosspost
http://forum.java.sun.com/thread.jspa?threadID=703918

Similar Messages

  • Perl script calling a java program

    Hello,
    I have the following perl script that executes a java program called TestSe. It passes its QUERY_STRING to the java program after printing it.
    #!/usr/bin/perl
    print "Content-type: text/html\n\n";
    $in = $ENV{'QUERY_STRING'};
    print $in;
    exec 'java TestSe '.$in;
    This script in placed in a cgi-bin directory on a server.
    This script works when i run it manually and hardcode a string value in $in by doing
    $in="Acheck";
    It prints 'Acheck' on the screen and invokes the java program with Acheck as the parameter.
    I tested it by typing
    'perl try.cgi' on the shell after logging into the server.
    However when I execute this script via. a browser then it does not exec the java program.
    The QUERY_STRING is the papameter passed to this script by an html form in a browser that invokes it. The script can print the value of $in in the new browser window that it creates but it is not execing the java program.
    Does anyone kow why?
    Thanks

    Perhaps java isn't in the PATH for the server

  • How to run Perl script in Java program?

    Some say that the following statement can run Perl script in Java program:
    Runtime.getRuntime().exec("C:\\runPerl.pl");
    But when I run it, it'll throw IOException:
    java.io.IOException: CreateProcess: C:\runPerl.pl error=193
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:63)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:566)
    at java.lang.Runtime.exec(Runtime.java:428)
    at java.lang.Runtime.exec(Runtime.java:364)
    at java.lang.Runtime.exec(Runtime.java:326)
    at test.runPerl.main(runPerl.java:16)
    Exception in thread "main"
    Where is the problem? In fact, I do have a Perl script named "runPerl.pl" in my C:/ directory. Could anybody tell me why it can't be run? Thanks in advance.

    Hello sabre,
    First of all thanks for your reply.
    I have tried like what you mentioned.
    Eventhough, i could get the exact error message.
    I could get the Exception
    "Exception:java.lang.IllegalThreadStateException: process hasn't exited"
    <code>
    import java.io.*;
    public class Sample{
    public static void main(String args[]) {
    String s = null;
    Process p;
    try
         p = Runtime.getRuntime().exec("tar -vf sample.tar");
         //p.waitFor();
         if(p.exitValue() == 0)
              System.out.println("CommandSuccessful");
         else
              System.out.println("CommandFailure");
    catch(Exception ex)
         System.out.println("Exception:"+ex.toString());
    </code>
    In this code, i tried to run the "tar command". In this command i have given -vf instead -xvf.
    But it is throwing
    "Error opening message catalog 'Logging.cat': No such file or directory
    Exception:java.lang.IllegalThreadStateException: process hasn't exited
    CommandFailure"
    "Error opening message catalog 'Logging.cat'" what this line means ie,
    I dont know what is Logging.cat could you explain me its urgent.
    Thanks in advance.
    Rgds
    tskarthikeyan

  • Run Perl script in JAVA

    Can we run perl scripts in java, still supporting perl API?
    Thanks a lot for help!

    I haven't tried it but I think 6.0 supports some
    scripting.But NOT perl!Sorry, I didn't mean some Perl Scripting. I meant some scripting and I wasn't sure what languages.

  • Running a Unix Script through a Java Program

    Hi !!!!!!!!! Can anybody plz suggest me an approach for the following queries -
    1.  How to execute a unix script through a java program ?
      2.  How to send the o/p of the script to a java program so that it can be used .

    import java.io.*;
    public RunScript
       public static void main(String args[])
          try
              Process p = Runtime.getRuntime().exec("script.sh");
              BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));     
              while ((line = input.readLine()) != null)
                 System.out.println(line);
              input.close();
          catch(Exception e)
              e.printStackTrace();

  • Can servlets/ jsp automatically run perl scripts and executables?

    I'm a student and am new to to servlets and web programming in general.
    I need to know if it's possible to run perl scripts and executables automatically from servlets/ jsp.
    The program I am planning on creating should have a client outside a firewall that uploads perl files to a gateway machine inside the firewall, the servlet should be able to run this perl file, and then pass the resulting file as an argument to an executable, to be run by another servlet on a different server.
    I've tried looking everwhere for an answer to this and am about to revert to a cgi based approach because I'm not sure if it would work so any help/ suggestions would be much appreciated.

    Hallo,
    I think using java Runtime will help. you can do Processes that execute shell or system commands through
    Process process = Runtime.getRuntime().exec("your perl scripts here!");
    Bye

  • Executing a perl script from within java application

    Hi,
    Does anyone knows a way to execute a perl script from within java.
    ---kirk

    Runtime.exec("perl myscript.pl");
    Of course whether that "works" depends on what the script does and where the java program runs.

  • Need to execute tcl script from a Java Program

    Hello,
    I need to execute a tcl script from a Java Program. But I do not know how to call the tcl Interpreter. Can anybody help me?

    Iam using the exec command as follows:
    Process proc =
    rt.exec("C:/SpirentConnect/engines/tcl/8.3.4/windows/s
    ctcl.exe C:/Hello.tcl");
    But Hello.tcl is not executed.And does that exact string work on the command line?
    And what is the return code from running it?

  • Can I run perl scripts on a iplanet App Server instead of web server

    Hello,
    We have some perl scripts running on a iWS 6.0 in DMZ (Tier1) which acess Oracle Server(Tier 3). I want to restrict machines on DMZ access Oracle server directly. Instead I want all the database calls to orignate from iPlanet App server on Tier 2. To make this happen I have to run Perl scripts on App server. Is this feasible as the J2EE iPlanet App can run only C++ or Java.. Any leads helps me lot..
    Thanks
    Sudhir Nallagangu

    According to the J2EE specs you should use EJBs and Servlets in the iAS! Running a perl script for db access sounds like good old cgi times.
    But generally it is possible to call a perl script from within iAS. But don't do it!

  • Running curl command from a java program using Runtime.getRuntime.exec

    for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
    To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
    I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
    Any ideas on why this might be happening?

    thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
    I am using 7.15 in my system.
    Below is the code which errors out.
    public int execCurlCmd(String command)
              String s = null;
              try {
                  // run the Unix "ps -ef" command
                     Process p = Runtime.getRuntime().exec(command);
                     BufferedReader stdInput = new BufferedReader(new
                          InputStreamReader(p.getInputStream()));
                     BufferedReader stdError = new BufferedReader(new
                          InputStreamReader(p.getErrorStream()));
                     // read the output from the command
                     System.out.println("Here is the standard output of the command:\n");
                     while ((s = stdInput.readLine()) != null) {
                         System.out.println(s);
                     // read any errors from the attempted command
                     System.out.println("Here is the standard error of the command (if any):\n");
                     while ((s = stdError.readLine()) != null) {
                         System.out.println(s);
                     return(0);
                 catch (IOException e) {
                     System.out.println("exception happened - here's what I know: ");
                     e.printStackTrace();
                     return(-1);
         }

  • Procedure to call shell script which invoke java program

    Hi
    I have requirement for a pl/sql procedure to invokes a shell script which calls java programs.
    I was using DBMS_SCHEDULTER to invoke the shell , the shell is getting invoked but it is not executing the java programs.
    appreciate your suggestions and advices .
    param1=$1
    param2=$2
    #echo "First parameter is:"$1
    #echo "Param1 is:"$param1
    if [ $# -eq 1 ]; then
    java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1
    elif [ $# -eq 2 ]; then
    java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1 $param2
    fi
    Regards

    user458361 wrote:
    Hi
    I have requirement for a pl/sql procedure to invokes a shell script which calls java programs.
    I was using DBMS_SCHEDULTER to invoke the shell , the shell is getting invoked but it is not executing the java programs.
    appreciate your suggestions and advices .
    param1=$1
    param2=$2
    #echo "First parameter is:"$1
    #echo "Param1 is:"$param1
    if [ $# -eq 1 ]; then
    java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1
    elif [ $# -eq 2 ]; then
    java -jar -Xmx512m abc.jar ${CONFIG_DIR} $param1 $param2
    fi
    RegardsYou are doing the equivalent of making THREE Left turns instead of a single Right turn
    Most likely the shell environment is woefully lacking in needed details
    add new line as below
    param1=$1
    param2=$2
    /usr/bin/env | /usr/bin/sort -o /tmp/capture.log
    # make sure above Fully Qualified Pathnames are correct for your system!
    After you invoke script from PL/SQL post content of /tmp/capture.log back here

  • Running a process within a java program

    Hi
    I have code that runs a process for performance monitoring on an installed system. When I run the code standalone as below, it runs fine. If I include the code below inside another java program, the process fails to execute and the status returned is non-zero (failed to execute).
    The process requires the PATH and LD_LIBRARY_PATH to be set which seem to be set correctly when i print them out. So, I am not sure why the process doesnot run when included within another running java program.
    Can someone please point out what I maybe missing?
    Thanks!!
    public class RunPerf
      private static final String CLASS_NAME = "RunPerf"; private static Process proc = null;
    public static void main(String[] args)
        String INSTALLPERF_SAW_UNIX_COMMAND = "sawexe" + " " + "-perf";
             StringBuffer path1 = new StringBuffer(30);StringBuffer ldlibpath1 = new StringBuffer(30);
        System.setProperty("user.home", "/home/user");
        StringBuilder commandToExecute = new StringBuilder();
       commandToExecute.append(System.getProperty("user.home"));
       commandToExecute.append(File.separator);
       commandToExecute.append("web");
       commandToExecute.append(File.separator);
       commandToExecute.append("bin");
       commandToExecute.append(File.separator);
         String path = System.getProperty("user.home")+"/server/bin/" + File.pathSeparator + System.getProperty("user.home")+ "/web/bin";
           path1.append( path );
           path1.append( File.separator );
           path1.append( System.getProperty("java.library.path") );
           path1.append( File.separator );
          String env_value = null;
         String[] ldargs = {"LD_LIBRARY_PATH"};
         for (String env: ldargs) {
                env_value = System.getenv(env);
             System.out.println("LD_LIBRARY_PATH value before setting property= " + env_value);
                if (env_value != null) {
               String newldlibpath = System.getProperty("user.home")+ "/server/bin/" + File.pathSeparator + System.getProperty("user.homee")+ "/web/bin" ;
                ldlibpath1.append(newldlibpath);
                ldlibpath1.append(File.separator);
                   ldlibpath1.append(env_value);
                   ldlibpath1.append( File.separator);
                    System.out.format("%s=%s%n", env,ldlibpath1.toString());
                } else {
                    System.out.format("%s is not assigned.%n", env);
                 commandToExecute.append(INSTALLPERF_SAW_UNIX_COMMAND);
                   String[] envp =   { "USER_HOME =" + "/home/user",          "PATH=" + path1.toString(), "LD_LIBRARY_PATH=" + ldlibpath1.toString() };
               int status = executeCommand1(commandToExecute.toString(), envp,null);
                   if(status != 0){
                          System.out.println("Unable to run perf Unix") ;
         public static int executeCommand1(String command,String[] envp, Logger logger) {
            String METHOD_NAME = "executeCommand1";
            if (logger == null) { logger = Logger.getAnonymousLogger();}
            logger.entering(CLASS_NAME, METHOD_NAME, new Object[] { command, envp});
            Runtime runtime = Runtime.getRuntime();
            runtime.addShutdownHook(new Thread() {
                        public void run() {
                            if (proc != null) {     try {  proc.destroy();  if (proc != null) { proc.destroy();  }
                                } catch (Exception e) {
                                    e.printStackTrace(); }      }      }     });               
                           int retVal = 0;
          File cwd = new File(System.getProperty("user.home")+ "/web/bin/");               
                           try {
                               if (envp != null) {   proc = runtime.exec(command, envp,cwd); }
                                       else {  proc = runtime.exec(command); }
                               Thread t_err =        new Thread(new StreamReader(proc.getErrorStream()));
                               t_err.start();
                               Thread t_in =     new Thread(new StreamReader(proc.getInputStream()));
                               t_in.start();
                               retVal = proc.waitFor(); } catch (IOException e) {        retVal = -1;   logger.severe("IOException");      }
                                     catch (Exception e) { retVal = -1;        logger.severe("Exception");                  }
                     logger.exiting(CLASS_NAME, METHOD_NAME, retVal);
                     return retVal;
    static class StreamReader implements Runnable {
            InputStream in;
            public StreamReader(InputStream genericStream) {   in = genericStream;   }
            public void run() {
                try {
                    String strTemp = null;
                    BufferedReader buffReader = new BufferedReader(new InputStreamReader(in));
                    while ((strTemp = buffReader.readLine()) != null) {
                        System.out.println(strTemp);                }
                } catch (Exception e) {               e.printStackTrace();            }        }    }}

    Either set up a script before the program runs or have the
    program write a script file which contains the statements
    that need to be executed. Then you will be able to
    execute the script with a call to
    Runtime.getRuntime().exec()Mark

  • Shell script for executing java program

    i want to write a shell script which will export the classpath and compile & run the java program.
    any references from where i can get that?

    Try typing "man sh" at the command prompt.
    Ultimately it'll end up looking a lot like this:
    #!/bin/sh
    CLASSPATH=/path/to/a.jar:/path/to/anther.jar
    JAVA_HOME=/path/to/where/you/installed/java
    $JAVA_HOME/bin/java your.classes.package.YourClass

  • How does one run a *.exe with a Java program?

    Hi,
    I'm looking for a way to run an executable (*.exe) or batch file (*.bat) from within a Java program.
    Any suggestions, leads, or examples appreciated.
    Thanks!

    Runtime.getRuntime.exec("pathTo/yourapp.exe");
    For any type of interpreted scripts, the interpreter should be added:
    Runtime.getRuntime().exec({ "command.com", "mybat.bat"});
    or
    Runtime.getRuntime().exec({"/bin/sh", "configure.sh"});

  • Specify a exe running from certain directory from java program

    Hi there,
    I had a java program, which will spawn some child process to run vb COM;
    what I wanted to do: have a child process start the COM from a specific diretory?
    IS there any way to do it from Java, like shell programming?
    Thanks

    I do all my portable shell stuff now in ant.. http://jakarta.apache.org/ant/
    it is an XML driven java script for doing builds.. but it can be used for shell scripting.
    They are also some java scripting languages like jPython but i am not very familiar with them.
    u can also get Cygwin and write unix shell scripts. www.cygwin.com
    hope this helps

Maybe you are looking for