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.

Similar Messages

  • 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 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

  • Converting Perl Scripts into Java Servlets

    Hello,
    I have just been assigned the job of converting some perl scripts into Java Servlets. The first problem i have run into is with quotes. The problem is in perl you can just print out blocks of html without worrying about the quotes. ie (name="joe"). It will be a pain if i have to delimit every quote that is in the html so that i can add it to my java string. I was just wondering if anyone knows of an easy way of accomplishing this task.
    Thanks,
    Jon

    jonhorsman said
       I have just been assigned the job of converting some perl
       scripts into Java Servlets.I was just wondering if anyone
       knows of an easy way of accomplishing this task. The easy way is to not do it - is there a business need to do this or just because someone likes java more than perl.
    But presuming there is a business need, then the easist way I can think (and certainly more interesting than doing it by hand) is to write a perl script that does it for you.

  • 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

  • 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!

  • 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..

  • Running sqlplus scripts from Java code?

    hi
    I need to programmatically run sqlplus scripts from Java code on a machine that doesn't have sqlplus installed.
    Is there any Java class library available for doing this?

    The Ant approach could probably work for me, thanks for the tip.
    The setup seems rather complex however, given the simplicity of the task. I would prefer just running a Java based SQL*Plus from in a separate process or doing this via an API that would allow me to run SQL*Plus scripts (parse script, substitute variables, run statements).
    Oracle SQL Developer v1.1 appears to include an API that does exactly this.
    The ScriptParser, Substitution and SQLPLUS classes in the oracle.dbtools.raptor.scriptrunner package (oracle.sqldeveloper.jar) seem to do just what I need based on my tests.
    Can I use these classes for this purpose in my application? Is repackaging allowed?
    Does Oracle have any plans for releasing this sort of functionality separately e.g. as part of the Instant Client?

  • How to run the perl script from java ?

    Hi , I need to run the pearl script from the server and to get the result of the script thro' java using SSH
    Is there any 3rd party SSH API in java ?
    Please help me out
    thanks in advance
    karthik

    This seems like a very strange thing to want to do.
    What is the perl script doing?
    Do other programs (not some shell script) access this server-side perl script from a different machine?
    If so how do they do it?
    What currently triggers the perl script to execute?
    What currently handles the output from the perl script?
    If you can answer these questions (and understand the answers) you should be able to come up with a different approach to this.
    You do not really want to call a remote perl script from a Java program, you want to achieve the effect you think that would have if you could do it.
    So find the answers to the above questions, write them on 3" x 5" cards and lay them out on your desk.
    What flow of control needs to happen? Which piece of code needs to produce or consume which piece of data?
    If that fails, ask you self or who ever is making you do this what are the use-cases?
    If you do not know what use-cases are or do not understand them well enough try reading
    Use Case Modeling (The Addison-Wesley Object Technology Series) by Kurt Bittner and Ian Spence (Paperback - Aug 30, 2002)
    http://www.amazon.com/s/ref=nb_ss_gw/002-7908514-4043267?url=search-alias%3Dstripbooks&field-keywords=use+cases&x=0&y=0
    It is a short and easy to read book on the subject and also one of the best.
    You MUST understand WHAT you are trying to achieve before you can decide HOW you are going to achieve it.

  • Calling perl script from java ---help needed

    I haven't been doing a lot with java lately and i'm building an app with netbeans and having some difficulty with my button calling an outside perl script I'm pasting the code and error below...any help would be greatly appreciated. It's running on fedora 9 pretty much default install...
    thanks.
    code:
    Runtime r = Runtime.getRuntime();
    Process p = null;
    String s = null;
    String cmd123[] = { "perl /home/deaddev/test1.pl" };
    try {
    p = r.exec(cmd123);
    catch {
    foo bar/etc/etc
    error:
    Oct 12, 2008 4:09:37 PM photomainmgr readToPerlActionPerformed
    SEVERE: null
    java.io.IOException: Cannot run program "perl /home/deaddev/test1.pl": java.io.IOException: error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:474)
    at java.lang.Runtime.exec(Runtime.java:610)
    at java.lang.Runtime.exec(Runtime.java:483)
    at photomainmgr.readToPerlActionPerformed(photomainmgr.java:117)
    at photomainmgr.access$000(photomainmgr.java:21)
    at photomainmgr$1.actionPerformed(photomainmgr.java:54)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:253)
    at java.awt.Component.processMouseEvent(Component.java:6101)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3276)
    at java.awt.Component.processEvent(Component.java:5866)
    at java.awt.Container.processEvent(Container.java:2105)
    at java.awt.Component.dispatchEventImpl(Component.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2163)
    at java.awt.Component.dispatchEvent(Component.java:4288)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4461)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4125)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4055)
    at java.awt.Container.dispatchEventImpl(Container.java:2149)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4288)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
    Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:164)
    at java.lang.ProcessImpl.start(ProcessImpl.java:81)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:467)
    ... 30 more
    error executing perl /home/deaddev/test1.pl

    jschell wrote:
    sabre150 wrote:
    As and alternative you can useString cmd123 = "perl /home/deaddev/test1.pl";Using the single string approach YOU have to do any quoting so with this line no quoting takes place and the script /home/deaddev/test1.pl will be executed.Although that should be true apparently it isn't. I have just run  
    Process p = Runtime.getRuntime().exec("perl /home/sabre/work/dev/perl/xxx.pl");
    new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
    new SyncPipe(p.getInputStream(), System.out).run();
    int returnCode = p.waitFor();
    System.out.println("Return code = " + returnCode);which correctly executes the perl script xxx.pl.
    P.S. SyncPipe is a Runnable that copies an InputStream to an OutputStream.
    Edited by: sabre150 on Oct 14, 2008 9:19 AM
    Interesting! Even though Runtime.exec() works with a single String, ProcessBuilder fails with this approach! You have to split the argument string. This certainly looks like a bug! Some while ago I looked at the source for Runtime.exec() to look at the differences between Runtime.exec() and ProcessBuilder and found that behind the scenes Runtime.exec() uses ProcessBuilder.
    More research is required.

  • Running perl scripts off the preinstall script during a pkgadd

    Hello,
    I'm trying to build a custom package (apache2 + mysql + php + other stuff) and get stuck on some stone wall that I can't figure.
    Correct me if I'm wrong in my assumptions, and if able, could you provide a work around ? Here it is :
    - The preinstall script must be in /bin/sh , /bin/bash or any valid shell
    - Must be run by root, 'f course
    Now.. As I'm not that strong on bash/sh scripting, I tried to call a perl script off my preinstall script. Somehow my preinstall script just never call the .pl .
    This leads me to my third assumption :
    - It is impossible, not permissible to run other scripts from the preinstall script.
    Basically the perl script checks for some users in /etc/passwd + /etc/group, checks for some directories, create a custom SMF manifest, etc etc . I pretty much want the .pl script to be run.
    The script itself is well packaged, correctly inserted in the package's pkgmap, and so on.
    Any ideas ?
    Thanks,
    Jeff

    The script itself is well packaged, correctly inserted in the package's pkgmap, and so on.http://docs.sun.com/app/docs/doc/817-0406/ch3enhancepkg-10289?a=view

  • Running perl programs through java.

    How do i run a perl program through java?
    arg.pl :
    while(<STDIN>)
    print;
    java program that I tried:
    import java.io.*;
    class runtime
        static Process p;
        static BufferedReader stdOutput;
        static BufferedWriter stdInput;
        public static void main(String args[]) throws IOException
            int i = 0;
            try{
                String cmd[] = new String[] {"perl","arg.pl"};
                p = Runtime.getRuntime().exec(cmd,null,new File("./"));
                stdOutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
                stdInput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
            catch(Exception ex){
                System.out.println("Unable to initiate Process : " + ex);
            stdInput.write("abcd\n");
            stdInput.write("1234\n");
            stdInput.write("efgh\n");
            stdInput.write("5678\n");
            stdInput.close();
            System.out.println(stdOutput.readLine());
            System.out.println(stdOutput.readLine());
            System.out.println(stdOutput.readLine());
            System.out.println(stdOutput.readLine());
    }This works well. But I need to read the output line by line as and when i give the standard input line by line to it.
    I tried the following :
    import java.io.*;
    class runtime
        static Process p;
        static BufferedReader stdOutput;
        static BufferedWriter stdInput;
        public static void main(String args[]) throws IOException
            int i = 0;
            try{
                String cmd[] = new String[] {"perl","arg.pl"};
                p = Runtime.getRuntime().exec(cmd,null,new File("./"));
                stdOutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
                stdInput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
            catch(Exception ex){
                System.out.println("Unable to initiate Process : " + ex);
            stdInput.write("abcd\n");
            stdInput.flush();
            System.out.println(stdOutput.readLine());
            stdInput.write("1234\n");
            stdInput.flush();
            System.out.println(stdOutput.readLine());
            stdInput.write("efgh\n");
            stdInput.flush();
            System.out.println(stdOutput.readLine());
            stdInput.write("5678\n");
            stdInput.flush();
            System.out.println(stdOutput.readLine());
            stdInput.close();
    }This doesn't work well. It just halts without any output.
    Can anyone help me?
    Edited by: Vijayakrishna on Dec 5, 2007 8:30 AM

    Let me be more specific.
    I want to use a class which will look something like this.
    import java.io.*;
    public class FindAnswer{
        Process p;
        BufferedReader stdOutput;
        BufferedWriter stdInput;
        public FindAnswer()
            try{
                String cmd[] = new String[] {"perl","arg.pl"};
                p = Runtime.getRuntime().exec(cmd,null,new File("./"));
                stdOutput = new BufferedReader(new InputStreamReader(p.getInputStream()));
                stdInput = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
            catch(Exception ex){
                System.out.println("Unable to initiate Process. Error: " + ex);
        public String getAnswer(String question)
            String answer = question;
            try{
                stdInput.write(question + System.getProperty("line.separator"));
                stdInput.flush();
                answer = stdOutput.readLine();
            catch(Exception ex){
                System.out.println("Exception. Error: " + ex);
            return answer;
        public void close()
            if (p != null) {
                try {
                    if (p.getInputStream() != null)
                        p.getInputStream().close();
                    if (p.getOutputStream() != null)
                        p.getOutputStream().close();
                    if (p.getErrorStream() != null)
                        p.getErrorStream().close();
                catch (Exception e) {
                    System.out.println("Exception in Closing Streams - " + e);
    }The perl program takes lot of initialization time. I dont want to run the program foreach question i have. I'll just create an object to this class and find and answer by passing question to the object's getAnswer method. Here, I dont know all the questions in the beginning itself. I'll know one by one only and I should find answer without terminating the process.
    Kindly help me in this.

  • ANM VA - run perl script to obtain and genarate reports.

    Good day,
    We have a customer who has an ANM deployment at a site. This is a HA deployment on RedHat. The customer created a perl script to run off an external host to generate reports. This was acheievd by querying the sqldatabase (dcm_ems). ANM version is 3.2. No problems.
    An additional ANM deployment was done on another site. ANM version 4.2. This deployment is the VA edition. They would like to deploy and run the same perl script.
    Is this possible on the VA Edition? Even with the RootPatch? Not sure of the level of access the patch provides, or if it is even recommened or would then still allow for the ANM to be supported? If possible, has the sqldatabase structure changed (suppose would need this for the guy's to ammend the script)? How would we obtain the "sqluser" and "sqlpwd" info for the perl script to use?
    Appreciate any guidance or feedback.
    Thank you in advance.
    Paul.

    Hi esteemed forum members,
    Any ideas or feedback anyone?
    Thanks.
    Paul.

  • Execute perl-script using java

    Hi All
    I would like to execute a perl script (inside a java app) and retrieve its output. This java program needs this output.
    Can someone give me information on how to do this ?
    Thanks a lot in advance
    Luca

    Ok, solved it:
    import java.lang.Runtime ;
    import java.io.* ;
    public class Test {
         public static void main ( String ARGV[] ) {
              Runtime r = Runtime.getRuntime() ;
              Process p = null ;
              DataInputStream dis = null ;
              String s ;
              try {
                   String cmd[] = new String[1] ;
                   cmd[0] = "./a.pl" ;
                   p = r.exec(cmd) ;
              dis = new DataInputStream(p.getInputStream());     // create file I/O
                   s = dis.readLine();     
                   System.out.println("|"+s+"|") ;
                   s = dis.readLine();     
                   System.out.println("|"+s+"|") ;
              catch(IOException e) {}
    }

  • Problem in running Perl script through oracle

    Hi,
    I am facing one problem in perl script.
    " I have one perl script which is interact with sybase database.We have migrated the sybase database to oracle successfully.Now i wanna to change the perl script to interact with oracle database.
    I am using the code like that for interacting the oracle database
    Old Code with sybase database : use DBI::Sybase::GFAS;
    New code with oracle database : Use DBI::oracle::GFAS;
    When i am running the perl script,Its showing the below mentioned error:
    Can't locate DBI/oracle.pm in @INC (@INC contains: C:\oracle\product\10.2.0\db_1
    \perl\5.8.3\lib\MSWin32-x86 C:\oracle\product\10.2.0\db_1\perl\5.8.3\lib/MSWin32
    -x86-multi-thread C:\oracle\product\10.2.0\db_1\perl\5.8.3\lib C:\oracle\product
    \10.2.0\db_1\perl\5.8.3\lib\MSWin32-x86 C:\oracle\product\10.2.0\db_1\perl\site\
    5.8.3 C:\oracle\product\10.2.0\db_1\perl\site\5.8.3\lib/MSWin32-x86-multi-thread
    C:\oracle\product\10.2.0\db_1\perl\site\5.8.3\lib C:\oracle\product\10.2.0\db_1
    \sysman\admin\scripts C:/Perl/lib C:/Perl/site/lib .) at hello.pl line 4.
    BEGIN failed--compilation aborted at hello.pl line 4.
    Anyone have any idea about this error.
    Thx in advance.

    If you look in the oracle home in the perl\site\5.8.3\lib\MSWin32-x86-multi-thread directory you will see two directories. Once is DBI and one is DBD.
    All you need in your perl program is a line 'use DBI'. It will use DBD automatically as and when required. You can specify the necessary connection information when you issue the DBI->connect statement.
    I have successfully managed to connect to Oracle databases and perform DML using the software installed by default. You don't need to download and install anything else.
    I'm no perl expert so maybe some functionality is missing using the interfaces provided by Oracle but for my needs it has sufficed.
    Hope this helps.

Maybe you are looking for

  • Mail app keeps re-caching all messages when it starts

    Hello In past 10 days i have a very big problem which gives me headaches already. The problem is ( i did not change anything!) mail.app keeps re-caching all messages and attachments everytime i start the app. I have over 40.000+ mails so you do the m

  • Can't import photos from DVD

    I have a DVD-ROM with a bunch of images on it. Works fine if I drag the folder(s) from it to my hard drive - but - trying to import in Aperture doesn't seem to work... There's one folder on the DVD & a bunch of subfolders in that. The import window i

  • How much loss in capturing from tape?

    Looks like the days of tape are numbered.  If they haven't already, everyone will be using tapeless formats before too long.  I have a large library of HD (miniDV format) tape.  When clients want raw footage, I copy tape-to-tape using two camcorders

  • Lock box  reason codes

    Dear gurus please advise as how we can uses reason codes with lock box file processing. We want to write off each individual invoice on customer open item if it is paid +/-60$. Can we use reason codes with lock box automatic processing, so that these

  • Can We use varient in APD

    Hi Friends , Here i am creating 3/4 querys and i want to load the result of these querys results into an transactional ODS ,i want to create varient for each of the query and use in this process .I am not sure that whether we can use Varient in APD P