Perl in java

hi guys
is there is other way to call perl program in java without using exec command
best regards

Use could use JNI. You could even write a PERL interpreter in Java. I think using Runtime.exec is the best way, though (barring routes like "Don't use Java" or "Don't use PERL").

Similar Messages

  • Embedding perl in Java

    Are there any good websites/tutorials about how to go about embedding/using perl code in Java?
    How is it done?
    thanks, B.

    Are there any good websites/tutorials about how to go
    about embedding/using perl code in Java?
    How is it done?
    thanks, B. Try these links:
    http://www.perl.com/cs/user/query/q/6?id_topic=29
    http://www.perldoc.com/perl5.6/pod/perlfaq3.html#How-can-I-compile-Perl-into-Java-

  • Perl from java

    hi ..
    i want to generate a graphical report after anlysing a log file... i have parsed it with perl....but how do u get the return values into the java prog to generate the graphical report..
    pls help me... i am new to perl with java........

    How about writing the perl script such that it outputs a file of data, then write a java program that reads the data and plots it?

  • Perl - c - java munmap_chunk(): invalid pointer

    I am trying to use the JNI invocation interface from within some C code which in turn is invoked from Perl (Perl -> C -> Java).
    The problem is, when the Perl process ends, i end up this:
    *** glibc detected *** /usr/bin/perl: munmap_chunk(): invalid pointer: 0xb68d3880 ***
    ======= Backtrace: =========
    /lib/i686/cmov/libc.so.6(+0x6b321)[0xb7e20321]
    /lib/i686/cmov/libc.so.6(+0x6c59e)[0xb7e2159e]
    /usr/bin/perl(perl_destruct+0x1290)[0x807dd30]
    /usr/bin/perl(main+0x95)[0x80642a5]
    /lib/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0xb7dcbc76]
    /usr/bin/perl[0x8064171]
    I am simply invoking this function once, which creates the JVM and later invokes DestroyJavaVM...
    static void test( void ) {
        JavaVM *jvm;
        JNIEnv *env;
        JavaVMInitArgs vm_args;
        JavaVMOption options[ 1 ];
        options[ 0 ].optionString = "-Djava.class.path=/tmp";
        vm_args.version = JNI_VERSION_1_6;
        vm_args.nOptions = 1;
        vm_args.options = options;
        vm_args.ignoreUnrecognized = 0;
        int ret = JNI_CreateJavaVM( &jvm, ( void** ) &env, &vm_args );
        if(ret < 0)
            printf("\nUnable to Launch JVM\n");
        else {
            if( (*env)->ExceptionOccurred( env ) )
               (*env)->ExceptionDescribe( env );
            (*jvm)->DestroyJavaVM( jvm );
    }Can anyone offer me any clues as to what may be happening here? I am guessing that DestroyJavaVM is not freeing the resources allocated by the JVM and this interferes with garbage collection in Perl...

    I am guessing that DestroyJavaVM is not freeing the resources allocated by the JVMThat definitely won't be it, as DestroyJavaVM() currently does nothing.
    I would take this in three steps:
    1. write a C main() that starts and stops the JVM correctly
    2. write a C test() that does nothing except get called by Perl correctly
    3. Have the test() start the JVM using the same code as at (1).
    I would also have a look at how you are building the C exe. In my experience on Windows, sharing the C RTL doesn't work in conjunction with the JVM. Some years ago I was a whizz at fixing this sort of thing but these days I just use a static library ;-)

  • Can i write on perl in java?

    can i write on perl in java?

    can i write on perl in java?Listen Sscotties, not to step on too many of your toes, but if you are going to answer the question, do it write. He did not ask how to write perl, but how to write on perl. So here is the REAL answer:
    public class IThinkThisIsHowWeWouldWritePerlInJava{
       public static void main(String []args){
         System.out.print("on perl"); // not 100% sure though, maybe someone else could help
    }

  • Interacting with perl through java.

    I'm trying to do something with Java that I haven't managed to do until now. I'm trying to interact with a perl process giving him input and reading output.
    I have a perl module that has several functions and the idea is to launch a process in a java program with the following line :
    perl -e 'while(<STDIN>) { eval $_ ; }'
    and then give the process the necessary input and the read the given output.
    For instance with the above line you can do the following:
    [user@host ~]$ perl -e 'while(<STDIN>) { eval $_ ; }'
    print "Hello World\n";
    Hello World
    Here is the code I'm using:
    import java.io.BufferedReader;
    public class ExecProgram {
    private static Runtime runtime;
    private static Process process;
    public static void main(String[] args) {
         runtime = Runtime.getRuntime();
         try {
         process = runtime.exec("/usr/bin/perl -e 'while(<STDIN>) { eval $_ ; }'");
              process = runtime.exec(cmd);
         } catch (IOException e) {
              System.err.println("Error executing process");
         PrintWriter out = new PrintWriter(process.getOutputStream());
         String commandLine = "print \"Hello World\n\"";
         out.println(commandLine);
         BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
         try {
         String line;
         while ((line = in.readLine()) != null)
              System.out.println("Output: "+line);
         } catch (IOException e) {
         System.err.println("Error reading output");
    As you can see I'm using Runtime class to interact with the process but nothing happens if replace the exec line with:
    process = runtime.exec("ls");
    I can see in the output the listing of the current directory.
    Have you ever tried something like this? Is this the correct way for doing this?

    Have you ever tried something like this? I have. Here's a rough sample:
        public static void main(String[] args) throws Exception {       
            String[] cmd = new String[]{
                "/usr/bin/perl",
                "-e",
                "while(<>){ eval or die $@; }"
            final Process p = Runtime.getRuntime().exec(cmd);
            new Thread(){
                public void run(){
                    try{
                        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
                        for(String line; (line = r.readLine()) != null; System.out.println("ProcessOUT:: "+line));
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            new Thread(){
                public void run(){
                    try{
                        BufferedReader r = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                        for(String line; (line = r.readLine()) != null; System.err.println("ProcessERR:: "+line));
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            new Thread(){
                public void run(){
                    try{
                        OutputStream out = p.getOutputStream();
                        for(int ii = 0; ii < commands.length; ii++){
                            System.err.println("Sending command: "+commands[ii]);
                            out.write(commands[ii].getBytes());
                            out.write('\n');
                            out.flush();
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            int exit = p.waitFor();
            System.err.println("Process exited with code: "+exit);
        static final String[]
            commands = {
                "print \"The road goes ever\\n\";",
                "print \"ever\\n\";",
                "print \"on.\\n\";",
                "exit 13;"
        ;

  • How to run Perl from Java

    Hi,
    I have a program written in Perl. I want to run the Perl program using Java. If there is a command which can allow me to call the perl program from Java program, please advise me.
    regards

    The most easy way is to use Runtime class to call "perl" to run your perl script.
    String sCmd = "c:\\yourPerlScriptLoc\\yourPerlScript.pl";
    Process p = Runtime.getRuntime().exec(sCmd);

  • Migrating app from Perl to Java

    Hello all,
    I am fairly a newbie to Java and have been handed a new project, and I think Java is the proper way.
    The current application is written entirely in Perl and using Perl2Exe is an executable that is used internally at our company. What the tool does is, reads a CSV file, gathers IP/hostname, authentication information than connects (telnet and/or SSH and/or SNMP) to the said IP/Hosts (all cisco devices) and does a bunch (12 of them) of "cisco 'show'" commands and gathers the output into text files. One per IP/hostname. Which is then read in by another 3rd party application.
    I think I have a fair grasp of what needs to happen to convert the application into OO. The question is what libraries do I need to use for, since I don't want to reinvent the wheel
    - Reading CSV
    - Telnet
    - SSH v1 & v2
    - SNMP v1 v2c (possibly v3)
    Any help would be greatly appreciated. If at all possible, I would like to use GPL and/or Apache Licensed libraries.
    Thank you.
    awm
    P.S. In case you're asking why we're switching is that Perl on Windows doesn't really support SSH as a tty application and its not easily writable. Python is the other language of choice but I just would hate to have to switch to it, its just a pain to write in.

    I would say you can do this in Java no problem and there's lots of support for all the stuff you mentioned. Also, you can find everything you need at www.google.com. Once you start coding, post any problems/errors you have and we can provide more specific help.

  • Using perl Inline::Java and the BO SDK

    Hi, I'm looking for someone who's successfully used BO SDK though the Inline::Java perl module. I have only so far been able to connect to the CMS. I was hoping to see examples of report development, user management, server management, anything.
    Thank you,
    Mike

    Hi All heres the code with the propper tags i think, as for smorgasbords comment, I realise the security issue with java, but my lecturer seems to think its a good idea. Now the java applet opens a stream to my perl script and sends it parameters which the perl script uses to create the file. So java isnt making the file on any computer, perl is creating it on the server (EasyPHP actually). The example code given by my lecturer does actually work however for reasons which neither myself or the lecturer cannot see, it just doesnt create the file (or even open the perl script for that matter, as i used a file monitor to check if the 'diag.pl' file was accessed). I hope ive cleared up any questions.
    Thanks
    Dave
    void btnSendPosting_actionPerformed(ActionEvent e) { //Send Posting Event
    name = txtName.getText();
    email = txtEmail.getText();
    message = txtareaText.getText();
    path = txtFilePath.getText();
    String url = "http://localhost/cgi-bin/diag.pl";
    System.out.println("Url entered");
    try
    theURL = new URL(url);
    System.out.println("Url prepaired");
    catch (MalformedURLException f)
    System.out.println("Bad URL: " + theURL);
    try
    System.out.println("Beggining Connection...");
    URLConnection connection = theURL.openConnection();
    connection.setDoOutput(true);
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.print("txtName="+name +"&txtEmail="+ email +"&txtMessage="+ message +"&txtPath="+path);
    out.close();
    System.out.println("End of Connection");
    catch (IOException f)
    System.out.println("Error Opening Connection");
    } //Send Posting Close bracket

  • Perl to Java translation

    What is the java equivalent of the following perl code?#!/usr/bin/perl
    use strict;
    use warnings;
    use Net::FTP;
    my $file = shift;
    my $server = 'domain.com'; (edited out)
    my $username = 'username'; (edited out)
    my $password = 'password'; (edited out)
    my $remote_dir = 'domain.com'; (edited out)
    my $ftp = Net::FTP->new($server) or die "can't connect to $server: $@";
    $ftp->login($username, $password) or die "can't login ", $ftp->message;
    $ftp->cwd($remote_dir) or die "can't cd to $remote_dir ", $ftp->message;
    $ftp->put($file) or die "can't transfer $file", $ftp->message;
    $ftp->quit;
    exit 1;Thank you!

    http://www.google.com/search?q=FTP+Java

  • Perl and java

    hi, does anyone know if you can get a string from a java applet and use it in perl.
    thanks

    There is no specific communication mechanism between applets and perl.
    To send data to a server-side perl script, you simply submit a form or send a GET request with the appropriate fields.

  • Using Perl From Java!

    Hi there, i have an assignment for university, part of it is to send data to a perl script through a Java applet. My perl script works, as i have tested it with a HTML form, however when i try it with java, i get nothing, nothing, no errors or warnings. Im using JBuilder6.
    I am convinced that there is a problem with my code and a connection is not being opened, my lecturer cant see what the problem is (im not too impressed!) so i come to you.
    All the perl does is create a file called test.txt and print within it the name, email..etc from the applet.
    Thanks in Advance, Dave Williams.
    JAVA:
    void btnSendPosting_actionPerformed(ActionEvent e) { //Send Posting Event
    name = txtName.getText();
    email = txtEmail.getText();
    message = txtareaText.getText();
    path = txtFilePath.getText();
    String url = "http://localhost/cgi-bin/diag.pl";
    System.out.println("Url entered");
    try
    theURL = new URL(url);
    System.out.println("Url prepaired");
    catch (MalformedURLException f)
    System.out.println("Bad URL: " + theURL);
    try
    System.out.println("Beggining Connection...");
    URLConnection connection = theURL.openConnection();
    connection.setDoOutput(true);
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.print("txtName="+name +"&txtEmail="+ email +"&txtMessage="+ message +"&txtPath="+path);
    out.close();
    System.out.println("End of Connection");
    catch (IOException f)
    System.out.println("Error Opening Connection");
    } //Send Posting Close bracket

    Hi All heres the code with the propper tags i think, as for smorgasbords comment, I realise the security issue with java, but my lecturer seems to think its a good idea. Now the java applet opens a stream to my perl script and sends it parameters which the perl script uses to create the file. So java isnt making the file on any computer, perl is creating it on the server (EasyPHP actually). The example code given by my lecturer does actually work however for reasons which neither myself or the lecturer cannot see, it just doesnt create the file (or even open the perl script for that matter, as i used a file monitor to check if the 'diag.pl' file was accessed). I hope ive cleared up any questions.
    Thanks
    Dave
    void btnSendPosting_actionPerformed(ActionEvent e) { //Send Posting Event
    name = txtName.getText();
    email = txtEmail.getText();
    message = txtareaText.getText();
    path = txtFilePath.getText();
    String url = "http://localhost/cgi-bin/diag.pl";
    System.out.println("Url entered");
    try
    theURL = new URL(url);
    System.out.println("Url prepaired");
    catch (MalformedURLException f)
    System.out.println("Bad URL: " + theURL);
    try
    System.out.println("Beggining Connection...");
    URLConnection connection = theURL.openConnection();
    connection.setDoOutput(true);
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.print("txtName="+name +"&txtEmail="+ email +"&txtMessage="+ message +"&txtPath="+path);
    out.close();
    System.out.println("End of Connection");
    catch (IOException f)
    System.out.println("Error Opening Connection");
    } //Send Posting Close bracket

  • Calling perl from java applets

    I have problems in executing PERL from a JAVA applet and Swing interface.
    I'm working under Windows 98.
    My aim is the following:
    When I click on the "Analizza" button,
    I want to execute a PERL program and automatically
    close the DOS window after completion. If there
    is an error, this error should be displayed in DOS.
    I wrote this piece of code
    public void actionPerformed(ActionEvent eventoUtente){
         String comandoPulsante = eventoUtente.getActionCommand();
              if (comandoPulsante == "Analizza"){
              Runtime rt = Runtime.getRuntime();
              try{
              Process pr= rt.exec("cmd -c c:\\command /c perl C:\\_webasco\\contatutto2.pl");
              catch(java.io.IOException ioEx)
              System.out.println("IOEx:"+ioEx.getMessage());
    I tried also with a Windows executable, ie I replaced the line
         Process pr= rt.exec("cmd -c c:\\command /c perl C:\\_webasco\\contatutto2.pl");
    with
         Process pr= rt.exec("command /c c:\\windows\notepad.exe");
    but in both cases nothing happens within the applet.
    What am I doing wrong????
    Any suggestions is warmly welcomed.
    Thank you
    Marina

    I know nothing about Perl, but the line
    if (comandoPulsante == "Analizza"){
    compares references not values and will always return false. Try:
    if (comandoPulsante.equals("Analizza")) {

  • Problem calling two perl modules from java in seperate threads(JVM CRASHES)

    Dear Friends,
    I have one severe problem regarding calling perl modules from java
    I had to call two perl modules simultaneously (i.e.) from two threads,,, but jvm crashes when one of the perl calls is exiting earlier
    I am unable to spot out why ....
    For calling perl from java ...., We are first calling C code from java using JNI and then Perl code from C
    All works fine if we call only one perl call at a time.... If we call them in a synchronized manner the JVM is not crashing .... But we don't want blocking..
    The following is the code snippet
    <JAVA FILE>
    class Sample
         static {
              System.loadLibrary("xyz");  // Here xyz is the library file generated by compiling c code
         public native void call_PrintList();
         public native void call_PrintListNew();
         Sample()
              new Thread1(this).start();     
         public static void main(String args[])
              System.out.println("In the main Method");
              new Sample().call_PrintList();
         class Thread1 extends Thread
              Sample sample;
              Thread1(Sample sam)
                   sample=sam;
              public void run()
                   sample.call_PrintListNew();     
    }<C FILE>
    #include <EXTERN.h>
    #include <perl.h>
    static PerlInterpreter *my_perl;
    static char * words[] = {"alpha", "beta", "gamma", "delta", NULL } ;
    static void
    call_PrintList(){
         printf("\nIn the Call method of string.c\n");
            char *wor[] = {"hello", "sudha", NULL } ;
               char *my_argv[] = { "", "string.pl" };
               PERL_SYS_INIT3(&argc,&argv,&env);
               my_perl = perl_alloc();
                   PL_perl_destruct_level = 1; //// We have mentioned this also and tried removing destruct call
               perl_construct( my_perl );
               perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
              PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
               perl_run(my_perl);
         dSP ;
            perl_call_argv("PrintList",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
    //     perl_destruct(my_perl);
    //          perl_free(my_perl);
    //           PERL_SYS_TERM();
    static void
    call_PrintListNew(){
    printf("In the new call method\n");
    char *wor[] = {"Hiiiiiiiiiiiiiii", "Satyam123333", NULL } ;
            char *my_argv[] = { "", "string.pl" };
            PERL_SYS_INIT3(&argc,&argv,&env);
            my_perl = perl_alloc();
    PL_perl_destruct_level = 1;
            perl_construct( my_perl );
            perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
            PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
            perl_run(my_perl);
            dSP ;
            perl_call_argv("PrintListNew",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
      //      perl_destruct(my_perl);
      //      perl_free(my_perl);
       //     PERL_SYS_TERM();
    void callNew()
    call_PrintListNew();
    void call ( )
    call_PrintList();
    //char *wor[] = {"hello","sudha",NULL};
    /*   char *my_argv[] = { "", "string.pl" };
          PERL_SYS_INIT3(&argc,&argv,&env);
          my_perl = perl_alloc();
          perl_construct( my_perl );
          perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
         PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
          perl_run(my_perl);*/
       //   call_PrintList();                      /*** Compute 3 ** 4 ***/
    /*      perl_destruct(my_perl);
          perl_free(my_perl);
          PERL_SYS_TERM();*/
        }And Finally the perl code
    sub PrintList
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
    sub PrintListNew
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
            }Please help me in this regard

    Dear Friends,
    I have one severe problem regarding calling perl modules from java
    I had to call two perl modules simultaneously (i.e.) from two threads,,, but jvm crashes when one of the perl calls is exiting earlier
    I am unable to spot out why ....
    For calling perl from java ...., We are first calling C code from java using JNI and then Perl code from C
    All works fine if we call only one perl call at a time.... If we call them in a synchronized manner the JVM is not crashing .... But we don't want blocking..
    The following is the code snippet
    <JAVA FILE>
    class Sample
         static {
              System.loadLibrary("xyz");  // Here xyz is the library file generated by compiling c code
         public native void call_PrintList();
         public native void call_PrintListNew();
         Sample()
              new Thread1(this).start();     
         public static void main(String args[])
              System.out.println("In the main Method");
              new Sample().call_PrintList();
         class Thread1 extends Thread
              Sample sample;
              Thread1(Sample sam)
                   sample=sam;
              public void run()
                   sample.call_PrintListNew();     
    }<C FILE>
    #include <EXTERN.h>
    #include <perl.h>
    static PerlInterpreter *my_perl;
    static char * words[] = {"alpha", "beta", "gamma", "delta", NULL } ;
    static void
    call_PrintList(){
         printf("\nIn the Call method of string.c\n");
            char *wor[] = {"hello", "sudha", NULL } ;
               char *my_argv[] = { "", "string.pl" };
               PERL_SYS_INIT3(&argc,&argv,&env);
               my_perl = perl_alloc();
                   PL_perl_destruct_level = 1; //// We have mentioned this also and tried removing destruct call
               perl_construct( my_perl );
               perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
              PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
               perl_run(my_perl);
         dSP ;
            perl_call_argv("PrintList",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
    //     perl_destruct(my_perl);
    //          perl_free(my_perl);
    //           PERL_SYS_TERM();
    static void
    call_PrintListNew(){
    printf("In the new call method\n");
    char *wor[] = {"Hiiiiiiiiiiiiiii", "Satyam123333", NULL } ;
            char *my_argv[] = { "", "string.pl" };
            PERL_SYS_INIT3(&argc,&argv,&env);
            my_perl = perl_alloc();
    PL_perl_destruct_level = 1;
            perl_construct( my_perl );
            perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
            PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
            perl_run(my_perl);
            dSP ;
            perl_call_argv("PrintListNew",  G_DISCARD, wor) ;
    PL_perl_destruct_level = 1;
      //      perl_destruct(my_perl);
      //      perl_free(my_perl);
       //     PERL_SYS_TERM();
    void callNew()
    call_PrintListNew();
    void call ( )
    call_PrintList();
    //char *wor[] = {"hello","sudha",NULL};
    /*   char *my_argv[] = { "", "string.pl" };
          PERL_SYS_INIT3(&argc,&argv,&env);
          my_perl = perl_alloc();
          perl_construct( my_perl );
          perl_parse(my_perl, NULL, 2, my_argv, (char**)NULL);
         PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
          perl_run(my_perl);*/
       //   call_PrintList();                      /*** Compute 3 ** 4 ***/
    /*      perl_destruct(my_perl);
          perl_free(my_perl);
          PERL_SYS_TERM();*/
        }And Finally the perl code
    sub PrintList
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
    sub PrintListNew
                my(@list) = @_ ;
                foreach (@list) { print "$_\n" }
            }Please help me in this regard

  • RFCLIB access from Perl / Java  - newbie question

    Hi folks,
    I am newbie with SAP. I am triying to access the SAP from my web application, wrote in PErl or JAva.
    I am trying to access the librfc, bit I would like to know:
    1) What software I need to install in my client side (the web server that host my web application)??
    2) Which software contains  the RFC SDK? or the RFC LIB?
    3) Should I runt the script to access the rfclib in the SAP server side???
    Please help me with this cruel doubt !!!

    Hi,
    download the SAP JAVA Connector (SAP JCO) from
    service.sap.com
    There are enough examples for java.
    Best Regards
    Frank

Maybe you are looking for