Do a perl command from applescript

I'd like to use Perl from AppleScript for text replacements. The snippet below works, however when the var haystackString starts to include apostrophes, this fails. I tried using AppleScript's "quoted form of" on haystackString however it fails I think because the shell command I'm using needs single quotes to enclose the commands being executed by Perl. Any tips? Thanks, Ted
set haystackString to "this this"
  set findString to "this"
  set replaceString to "that"
set shellscript to ("perl -e '$s=\"" & haystackString & "\";$toFind=\"" & findString & "\";$replaceWith =\"" & replaceString & "\";$s =~ s/$toFind/$replaceWith/g;print $s;'") as string
  set testString to do shell script shellscript

Hi,
Ted Fitzpatrick wrote:
however it fails I think because the shell command I'm using needs single quotes to enclose the commands being executed by Perl. Any tips? Thanks, Ted
Yes, that's right.
Solution, use the arguments:
set haystackString to "can't  can't"
set findString to "can't"
set replaceString to "that's all"
set args to (quoted form of haystackString) & " " & (quoted form of findString) & " " & quoted form of replaceString
set testString to do shell script "perl -e '$s=\"$ARGV[0]\";$s =~ s/$ARGV[1]/$ARGV[2]/g; print \"$s\"' " & args

Similar Messages

  • Launchd fails to execute a perl command from a shell script

    Hello all,
    i have a little script that runs rsync. I use perl to add a timestamp to each line of output. Basically it goes like this:
    #!/bin/bash
    rsync -avz $sourceFolder $destinationFolder 2>&1 | perl -e "while(<>){s/^/$(date "+%Y-%m-%d %H:%M:%S") [rsync_backup.daily] /g; print;}"
    Invoking this script from terminal works perfectly! Invoking it via launchd however fails. There is no error thrown, it just seems to not proceed.
    Any help is appreciated.
    Cheers.

    This is the output from the shell:
    /Users/sadmin/Library/rsync_backup
    uid=501(sadmin) gid=20(staff) groups=20(staff),501(com.apple.local.ard_admin),256(com.apple.access_vpn),403(c om.apple.sharepoint.group.2),204(_developer),100(_lpoperator),98(_lpadmin),81(_a ppserveradm),80(admin),79(_appserverusr),61(localaccounts),12(everyone),406(com. apple.sharepoint.group.5),502(com.apple.local.ard_reports),253(com.apple.access_ chat),252(com.apple.access_addressbook),401(com.apple.access_screensharing),504( com.apple.local.ard_manage),503(com.apple.local.ard_interact),250(com.apple.acce ss_afp),404(com.apple.sharepoint.group.3),500(com.apple.access_ssh),257(com.appl e.access_backup),254(com.apple.access_calendar),402(com.apple.sharepoint.group.1 ),255(com.apple.access_mail),251(com.apple.access_smb),405(com.apple.sharepoint. group.4),407(com.apple.sharepoint.group.6)
    de.open-service.rsync_backup.daily.sh
    0
    TERM_PROGRAM=Apple_Terminal
    SHELL=/bin/bash
    TERM=xterm-color
    TMPDIR=/var/folders/A5/A5M1umP6EsKqyAig3q3Bak+++TI/-Tmp-/
    Apple_PubSub_Socket_Render=/tmp/launch-VgtdY6/Render
    TERM_PROGRAM_VERSION=273.1
    USER=sadmin
    COMMAND_MODE=unix2003
    SSH_AUTH_SOCK=/tmp/launch-4Jjpml/Listeners
    __CF_USER_TEXT_ENCODING=0x1F5:0:3
    PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin :/usr/X11/bin
    PWD=/Users/sadmin/Library/rsync_backup
    LANG=de_DE.UTF-8
    HOME=/Users/sadmin
    SHLVL=2
    LOGNAME=sadmin
    DISPLAY=/tmp/launch-219jsQ/org.x:0
    _=/usr/bin/printenv
    rsync is /opt/local/bin/rsync
    perl is /usr/bin/perl
    This is the output via launchd:
    uid=501(sadmin) gid=20(staff) groups=20(staff),501(com.apple.local.ard_admin),256(com.apple.access_vpn),403(c om.apple.sharepoint.group.2),204(_developer),100(_lpoperator),98(_lpadmin),81(_a ppserveradm),80(admin),79(_appserverusr),61(localaccounts),12(everyone),406(com. apple.sharepoint.group.5),502(com.apple.local.ard_reports),253(com.apple.access_ chat),252(com.apple.access_addressbook),401(com.apple.access_screensharing),504( com.apple.local.ard_manage),503(com.apple.local.ard_interact),250(com.apple.acce ss_afp),404(com.apple.sharepoint.group.3),500(com.apple.access_ssh),257(com.appl e.access_backup),254(com.apple.access_calendar),402(com.apple.sharepoint.group.1 ),255(com.apple.access_mail),251(com.apple.access_smb),405(com.apple.sharepoint. group.4),407(com.apple.sharepoint.group.6)
    /Users/sadmin/Library/rsync_backup/de.open-service.rsync_backup.daily.sh
    0
    SHELL=/bin/bash
    TMPDIR=/var/folders/A5/A5M1umP6EsKqyAig3q3Bak+++TI/-Tmp-/
    USER=sadmin
    PATH=/usr/bin:/bin:/usr/sbin:/sbin
    PWD=/
    SHLVL=1
    HOME=/Users/sadmin
    LOGNAME=sadmin
    _=/usr/bin/printenv
    rsync is /usr/bin/rsync
    perl is /usr/bin/perl

  • How to call external Perl routines from Pl/SQL - Urgent

    Available software in the Test Environment:
    1. Sun Unix 2.8
    2. Oracle 8.1.7 ( 8i)
    3. Perl 5
    Iam trying to call/execute perl scripts from PL/SQL using the DEMO_RDBMS.mk. I am able to call C scripts from PL/SQL, but actually want to call Perl scripts.
    The steps followed for for C are -
    1. Create and compile a simple C program to execute a unix command (eg., touch a file).
    2. Make a shared library of the above compiled program (object), i.e., load the compiled object module into a dynamic load library.
    3. Declare the above library in Oracle using SQL*Plus.
    4. Define a PL/SQL function or procedure to call the external routine.
    5. Test the external routine.
    The above steps run good for a C program, but step 2 fails when run for a Perl script.
    When I tried to use the following command for step 2 -
    make -f $ORACLE_HOME/rdbms/demo/demo_rdbms.mk extproc_callback \
    SHARED_LIBNAME=cmd_lib.so \
    OBJS=tst_cmd.pl
    got the following error -
    ld: fatal: file tst_cmd.pl: unknown file type.
    ld: fatal: File processing errors. No output written t cmd_lib.so
    *** Error code 1
    This gives me an indication that demo_rdbms.mk does not understand/interpret Perl scripts. Going through the demo_rdbms.mk suggests the same.
    My questions is - How do we call external Perl scripts/routines from PL/SQL ??
    Do I have to get a different version of "demo_rdbms.mk" ?
    PS: The perl scripts used above (tst_cmd.pl) is error free and works as intended in the unix environment.

    Iam trying to call/execute perl scripts from PL/SQL using the DEMO_RDBMS.mk. I am able to call C scripts from PL/SQL, but actually want to call Perl scripts. Well, C is a "compiler" language and Perl is interpreted. In a sense, C is not "scripts".
    When I tried to use the following command for step 2 -
    make -f $ORACLE_HOME/rdbms/demo/demo_rdbms.mk extproc_callback \
    SHARED_LIBNAME=cmd_lib.so \
    OBJS=tst_cmd.pl
    got the following error -
    ld: fatal: file tst_cmd.pl: unknown file type.
    ld: fatal: File processing errors. No output written t cmd_lib.soI guess this compiles an extproc "stub" with your object file, generating an external procedure. So the object file really needs to be an object file :-)
    My questions is - How do we call external Perl scripts/routines from PL/SQL ??I'd guess you need an embedded Perl interpreter in the external procedure.
    Not much help though I'm afraid :-/
    Cheers
    Fredrik

  • Shell or perl script from OS command_Sender File Channel

    Hi All,
    I am trying to execute a perl script from the File Sender Channel(NFS), OS command Before Message Processing. The script works fine if i run it from the shell. But when PI calls the script,  the script does not get executed. The audit logs mention that the OS command has been called.
    I tried using:
    1) /<fullpath>perlScript.pl /<fullpath>filename.dat
    2) perl /<fullpath>perlScript.pl /<fullpath>filename.dat
    Both these commands work fine when i execute them on the shell.
    I am on solaris and PI 7.0. The permission for the perl script and input files are all 777.
    FYI.. i am using this perl script to transpose a complex file and make it # delimited file.
    I have already read the blogs for OS command and executed some sample scenarios successfully.
    I tried to call a shell script that does the same functionality as the perl script. Even that does not work.
    Also, wrote a shell script to call the perl script inside it. No luck.
    eg:
    touch /fullpath>/create_before.dat
    perl /<fullpath>perlScript.pl /<fullpath>filename.dat
    touch /<fullpath>/create_after.dat
    In this case, the create_before.dat and create_after.dat is getting created but the perl is not called. I know this because i cant see the output files of the perl script.
    Regards,
    Balaji
    Edited by: Balaji M on Oct 30, 2008 2:36 PM

    Hi,
    The problem is fixed. The shell or perl both have logic to transpose a non industry starndard file to the delimited file which PI can use an FCC to pick up.
    This was the fix:
    we need to mention the shell the script is going to be run in.
    In the shell script we mentioned --> *#!/usr/bin/bash* as the first line
    normally, when we use the command -- which bash on the unix command prompt, it tells us the path for the bash used.
    another option --> #!/usr/bin/ksh
    again, on the command prompt -- which ksh command will tell us what ksh is being used.
    If the script is a simple one that does copy or move commands, i believe we need not use the commands above. But is a good practice to have them in the script.
    Regards,
    Balaji
    Edited by: Balaji M on Nov 3, 2008 4:38 PM

  • Calling perl script from PLSQL

    Hi All,
    I have created Java stored procedure and oracle function to execute the os commnad, this works fine for calling batch scripts but when i used same function to call perl script,
    like how we call in batch script
    perl <script name> the sql gets hanged.
    Is it possible to call perl like this?
    or is their any other way to call from plsql
    Thanks Chandra

    Are you able to run that perl script at DOS command line?
    Did you call the perl script directly from the java proc or you put the perl command line in a DOS .BAT scirpt and called that from the java proc?

  • Running a Excel VBA Addin from Applescript

    Hi,
    I have created a VBA script in Excel 2011.  I want this scripot to be availbale to any workbook I open up in Excel so I have set the script as an Add-in.  Then I want to be abke to run this script from Applescript.  The final plan is to have an automater workflow which allows me to drag and drop an excel file onto it which will open the file, run the script I have told it to run and save the file again.
    I think it is a referencing issue I have, I'm using the "run VB macro" command but I am getting the referencing wrong somewhere along the line.  If anyone can help or point me in the direction of some good documentation it would be really helpful.
    Thanks

    the problem is that you keep trying to open the workbook when it is already open. in the attached code you will that I search to see if the workbook is open. If it is then I set it to be the active workbook and run the macro. If not then i open it and then run the macro.
    try the attached code and see if it works for you. You will hace to make sure that all the references are closed and that the comparison functionality works for you. I just kinda hacked this together as a proof of concept for you.
    Message Edited by Joe_H on 11-17-2009 12:04 PM
    Joe.
    "NOTHING IS EVER EASY"
    Attachments:
    excel_run_macro without open.vi ‏20 KB

  • Running java command from DOS prompt

    Hi,
    When I run java from the DOS prompt (NT) in any other location than the JDK bin directory, I get the following error:
    Error opening registry key 'Software\JavaSoft\Java Runtime Environment'
    My understanding is to be able to run this from anywhere you need to add the tools.jar file to the CLASSPATH, which I have done.
    There is no entry in the Registry for Software\JavaSoft...etc, has anyone any idea what my problem is and how I can solve it?
    Thanks in advance

    Hi,
    I am running Java 2 SDK, Standard Edition Version 1.2.2 running on NT. It was installed as part of Oracles JDeveloper IDE and is running on NT.
    All I want to be able to do is run java from the command line e.g. 'java myclass', to run a standalone Java program. I can run 'javac myclass.java' to compile the program without any problems, but my understanding is that to do this all I need is to have the '.../java1.2/bin' directory included in the 'PATH' variable, whereas to run the java runtime you need to include the tools.jar in the CLASSPATH variable.
    As I said previously I can run the 'java myclass' command from the '../java1.2/bin' directory, just not from anywhere else. As for whats in the code, does not matter you should be able to type just java on the command line and it will come back with an error prompting for the class name. Here is an example of what happens:
    I:\>java
    Error opening registry key 'Software\JavaSoft\Java Runtime Environment'
    However if I change to the correct directory, I get:
    D:\oracle\JDev32\java1.2\bin>java
    Usage: java [-options] class [args...]
    (to execute a class)
    or java -jar [-options] jarfile [args...]
    (to execute a jar file)
    where options include:
    -cp -classpath <directories and zip/jar files separated by ;>
    set search path for application classes and resources
    -D<name>=<value>
    set a system property
    -verbose[:class|gc|jni]
    enable verbose output
    -version print product version
    -? -help print this help message
    -X print help on non-standard options
    The contents of my PATH and CLASSPATH variable are shown below, Thanks again.
    I:\>PATH
    PATH=D:\oracle\BIN;D:\oracle\Apache\Perl\5.00503\bin\mswin32-x86;C:\Program Files\Oracle\jre\1.1.7\b
    in;D:\oracle\ora8i\bin;C:\DMINT40\Win32\Bin;C:\WINNT\system32;C:\WINNT;C:\Program Files\Symantec\pcA
    nywhere;d:\oracle\jdev32\java1.2\bin;d:\downloads\oraxml\bin;d:\oracle\jdev32\java1.2\lib\tools.jar
    I:\>echo %CLASSPATH%
    d:\oracle\jdev32\java1.2\lib\tools.jar;d:\oracle\apache\apache\htdocs\web-inf\classes;d:\oracle\apac
    he\jserv\servlets

  • Passing variables from Applescript to bash

    Hello,
    I'm trying to pass variables from Applescript to bash using the following code
    #!/bin/bash
    osascript <<EOF
    tell application "SystemUIServer"
    set username to text returned of (display dialog "Enter your name" with icon caution default answer ""  buttons{"Continue"})
    set macname to text returned of (display dialog "Enter name of your Mac" with icon caution default answer ""  buttons{"Continue"})
    do shell script "export USERNAME=" & quoted form of username & " && export MACNAME=" & quoted form of macname
    end tell
    EOF
    echo "USERNAME is $USERNAME, MACNAME is $MACNAME"
    but no luck
    Mac-mini:Downloads admin$./new.command
    USERNAME is , MACNAME is
    Any help would be greatly appreciated.

    I just realized you are returning 2 variables.  That can still be handled by echoing/printing the values, you just have to parse the output, or use other tricks.
    VALUES=( $(osascript -e '...') )
    This would make VALUES an array, with each array element containing one space separate return value from osascript
    USERNAME=${VALUES[0]}
    MACNAME=${VALUES[1]}
    If USERNAME or MACNAME could have spaces in them, you would need to use some kind of separator character.  For example if you use @ as the separator you could do something like:
    VALUES=$(osascript -e '...')
    USERNAME=${VALUES%@*}
    MACNAME=${VALUES#*@}
    which will %@* will delete everything starting with the @ til the end of the string, and #*@ will delete everything from the beginning of the upto and including the @.
    Another trick is to have the return values be properly formed shell variable assignments such as
    print "USERNAME='your user name' MACNAME='Your Mac Name' " -- I'm making this up as I do not really know Applescript, so you will have to figure out how to get Applescript to print something that looks like
    USERNAME='your user name' MACNAME='Your Mac Name'
    In your shell script you have code that looks like:
    VALUES=$(osascript -e '...')
    eval $VALUES
    The eval will execute whatever is stored in $VALUES, and if that happens to look exactly like shell variable assignments, you get the variables created in the current shell context, where can use them.

  • Sending sysex commands from MainStage

    Has anyone figured out a way to send sysex sequences from MainStage when changing patches? I need to use sysex to switch one of my keyboards between its "Program" and its "Combi" mode and I don't see anything obvious in MS 2 to do this.
    I suppose it will be necessary to use an external utility like MidiPipe or Bidule or Max to listen for special MIDI commands from MainStage and then generate sysex messages but I thought I'd check first to see if anyone has an easier method.

    AFAIK - there is no way to send sysex from MainStage 2. Maybe Applescript can do it? MainStage can execute Applescripts.

  • Creating keywords from AppleScript

    Hi!
    I am trying to create and assign keywords using AppleScript.
    I have searched the web and found lots of dated articles. The gist is that assigning keywords requires for them to created first. In past versions of iPhoto this was impossible for lack of a "make new keyword" command.
    iPhoto'11 does seem to be able to create new keywords from AppleScript. I just can't get it to work.
    In its most basic version, my script looks like this:
    tell application "iPhoto"
    make new keyword with properties {name:"myTest"}
    assign keyword string "myTest"
    end tell
    This fails with the message "The at parameter is missing for make."
    Now I wonder where "at" I should create the keyword.
    Is the "make new keyword" command still broken?
    Best,
    Pierre

    May get an answer here but probably more likely in the using SL forum - http://discussions.apple.com/forum.jspa?forumID=1339&start=0
    LN

  • Calling perl script from labview

    Hi,
    I have a perl script and I would like to call the perl script from Labview
    anyone can help me with that?
    I used system exec but I'm getting an error.
    Anyone have a working example like calling a simple perl script from Labview.
    Thanks
    SL Ong

    Hi,
    Thanks for the reply from everyone.
    The attached is my code to call Perl script and after calling this, I need to query the Perl Script by sending command like @help. Do they have a way to query the Perl script by sending command like @help and get the return result. 
    I think Joseph you are right, but how do I get the return result if I invoke it in a separate dos session.
    SL Ong

  • Perl command not working throgh database.

    Hello,
    I am using perl command to convert unix format to dos format.
    I have written perl command in shell script and call shell script though database.
    Suddenly perl command is not working though database call.
    I can convert file using perl command through command promt.
    What could be the issue?

    user10540254 wrote:
    What could be the issue?Environment. When making that o/s call to run the perl script from inside Oracle, an external o/s process is created. This process executes the perl script. This process needs a valid environment (e.g PATH variable and others) in order to find the Perl run-time system, the required commands and libraries and so on.
    If the process does not have a valid environment, it will fail. You can test that manually by logging on to the server, and running the command unset PATH before executing the Perl script.
    One approach to this, is not to call something like the perl script directly. Instead create a shell wrapper script. In this script set a valid environment and then have it execute the perl script with the required command line parameters. Typically a shell script can always be executed (despite minimal environment settings), as long as you fully qualify the location (path) of the script.

  • Running python script with system arguments from applescript

    Hi,
    I am trying to run a python code from within applescript. A string should be passed as an argument to the python script, i.e. from the terminal, I would do the following
    cd /Users/thatsme/Library/Scripts/myfolder
    python my_python_file.py abcdefg
    There are two ways I figure I could do this in applescript. "abcdefg" are contained in the variable strNote
    a) directly:
    do shell script "cd /Users/thatsme/Library/Scripts/myfolder; python my_python_file.py " & strNote
    b) calling Terminal
    tell application "Terminal"
      activate
              do script "cd /Users/claushaslauer/Library/Scripts/OO_latex; python my_python_file.py " & strNote
    end tell
    I would prefer option a) as I don't really want to have Terminal windows popping up. The strange thing is, that I see in the applescript results window the result of the print statements in the python script, but no output is generated (the python script contains a few os.system() commands.
    Option b) does what it is supposed to be doing, however, applescript does not wait until the script is finished running.
    Why does option a) nor work, and what do I need to change to make it work?

    Thank you guys for your help, this is really weird.
    Here is my full applescript
    set strNoteQ to "1+1=2"
    (* for whatever reason, this does not work *)
    do shell script "cd /Users/claushaslauer/Library/Scripts/OO_latex; python create_latex_pdf.py " & strNoteQ
    Below is my python skript.
    When I call it as
         python create_latex_pdf.py 1+1=2
    it creates a wonderful pdf.
    With the applescript above, it prints the print statements, it also generates the latex file temp.tex -- correctly, so I assume the string in this example is ok.
    However, it does not execute the latex related commands (the three os.system calls)
    Is it not a good idea / not possible to execute os.system in a python script that is called from applescript? <sorry if I had brought all the attention to the string issue>
    here is the python script:
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import sys
    import os
    import datetime
    import time
    def main():
        str_latex_note = sys.argv[1]
        print "%s" %  str_latex_note
        preamble = """\documentclass{article}
    \usepackage{amsmath,amssymb}
    \pagestyle{empty}
    \\begin{document}
    {\huge
    %s
    \end{document}"""% (str_latex_note)
        ## write latex file
        cur_path = r'/Users/mypath/Library/Scripts/OO_latex'
        cur_file = "temp.tex"
        fobj = open(os.path.join(cur_path, cur_file), 'w')
        fobj.writelines(preamble)
        fobj.close()
        ## process latex file
        print cur_path
        os.chdir(cur_path)
        cmd = 'latex temp.tex'
        print cmd
        print "running latex"
        os.system(cmd)
        cmd2 = 'dvips -E -f -X 1200 -Y 1200 temp.dvi > temp.ps'
        print "running dvips"
        os.system(cmd2)
        cmd3 = 'epstopdf temp.ps'
        print "running epstopdf"
        os.system(cmd3)
        print "done!"
    if __name__ == '__main__':
        main()

  • 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

  • O/s commands from PL/SQL

    hi all..
    i want to execute operating system commands from PL/SQL..
    particulary imp command....
    i have used the f/wg approach but while i execute the imp command it does not responds me any output..
    I have to kill the process from o/s.
    prodn is my user
    --AS SYS user
    begin
    dbms_java.grant_permission( 'PRODN',
    'SYS:java.io.FilePermission',
    '/oracle/product/9.2.0/bin/imp',
    'execute' );
    dbms_java.grant_permission
    ('PRODN',
    'java.lang.RuntimePermission',
    'writeFileDescriptor' );
    end;
    ---------------------------------AS PRODN user
    create or replace and compile
    java source named "Util"
    as
    import java.io.*;
    import java.lang.*;
    public class Util extends Object
    public static int RunThis(String args)
    Runtime rt = Runtime.getRuntime();
    int rc = -1;
    try
    Process p = rt.exec(args);
    int bufSize = 4096;
    BufferedInputStream bis = new BufferedInputStream(p.getInputStream(),
    bufSize);
    int len;
    byte buffer[] = new byte[bufSize];
    // Echo back what the program spit out
    while ((len = bis.read(buffer, 0, bufSize)) != -1)
    System.out.write(buffer, 0, len);
    rc = p.waitFor();
    catch (Exception e)
    e.printStackTrace();
    rc = -1;
    finally
    return rc;
    create or replace
    function RUN_CMD(p_cmd in varchar2) return number
    as
    language java
    name 'Util.RunThis(java.lang.String) return integer';
    create or replace procedure RC(p_cmd in varchar2)
    as
    x number;
    begin
    x := run_cmd(p_cmd);
    end;
    i executed the command as follows in sql>
    BEGIN
    rc('/oracle/product/9.2.0/bin/imp tim/tim file=/home/oracle/vas4359.dmp log
    =log1.log');
    END;
    it runs fine creates log1.log in / home/oracle but there is no output in
    log1.log file.
    I have to kill the process as follows after which sql> displays me :
    "PL/SQL procedure successfully completed."
    [oracle@msebdb oracle]$ ps aux|grep imp
    oracle 20052 0.0 0.2 12732 4328 ? S 11:57 0:00 /oracle/product/
    .2.0/bin/imp file=/home/oracle/vas4359.dmp log=log1.log
    oracle 20102 0.0 0.0 3692 652 pts/2 S 12:03 0:00 grep imp
    Note:There is no tim user.. i just want to get error in my log file..
    my further steps are to read this log file and send email/notifications to users.
    my main program is as f/ws:
    /*imp and check log file*/
    create or replace procedure abc
    as
    v_exists boolean;
    v_exists_log boolean;
    ex_open BOOLEAN;
    flen NUMBER;
    bsize NUMBER;
    vInHandle_open utl_file.file_type;
    vInHandle_open_log utl_file.file_type;
    v_filelog utl_file.file_type;
    v_fl utl_file.file_type;
    v_pth varchar2(60);
    v_fnm varchar2(60);
    v_file_exists varchar2(60);
    v_logline varchar2(30) ;
    v_search varchar2(30) :='ORA-';
    vNewLine VARCHAR2(32767);
    cursor c_fname is
    select full_pth ,f_name from upld_file_t where f_name in
    (select f_name from tbl_file_nm where typ_file='D' AND DEL_FLG='N');
    BEGIN
    for v_sec in c_fname
    loop
    utl_file.fgetattr(LOCATION=>'ORALOAD',
    FILENAME=>v_sec.f_name,
    FEXISTS=>v_exists,
    FILE_LENGTH=> flen,
    BLOCK_SIZE=>bsize);
    if v_exists
    THEN
    dbms_output.put_line('File Exists' || v_sec.f_name);
    v_file_exists:=v_sec.f_name;
    --dbms_output.put_line('v_file_exists ' || v_file_exists);
    dbms_output.put_line('File Length: ' || TO_CHAR(flen));
    dbms_output.put_line('Block Size: ' || TO_CHAR(bsize));
    dbms_output.put_line(' before file open');
    vInHandle_open := utl_file.fopen('ORALOAD',v_sec.f_name,'R',32767);
    -- dbms_output.put_line(' after file open');
    -- do whater with teh file data
    v_fl:=utl_file.fopen('ORALOAD','v_sec.f_name','W');
    dbms_output.put_line('v_sec.f_name');
    IF utl_file.is_open(vInHandle_open)
    THEN
    /*if log file exists..*/
    utl_file.fgetattr(LOCATION=>'ORALOAD',
    FILENAME=>v_sec.f_name||'.log',
    FEXISTS=>v_exists_log,
    FILE_LENGTH=> flen,
    BLOCK_SIZE=>bsize);
    if v_exists_log
    then
    dbms_output.put_line('file' ||v_sec.f_name||'.log');
    v_filelog :=utl_file.fopen('ORALOAD',v_sec.f_name||'.log','W',32767);
    LOOP
    BEGIN
    UTL_FILE.PUT(v_filelog,'ORA-');
    exit;
    END;
    END LOOP;
    else
    dbms_output.put_line('File not found' || v_sec.f_name);
    END IF;
    UTL_FILE.fclose(v_filelog);
    dbms_output.put_line('Closed File ' || v_sec.f_name|| '.log');
    END IF;
    /*imp THE FILE and read log file*/
    utl_file.fgetattr(LOCATION=>'ORALOAD',
    FILENAME=>v_sec.f_name||'.log',
    FEXISTS=>v_exists_log,
    FILE_LENGTH=> flen,
    BLOCK_SIZE=>bsize);
    if v_exists_log
    then
    dbms_output.put_line('file' ||v_sec.f_name||'.log');
    v_filelog :=utl_file.fopen('ORALOAD',v_sec.f_name||'.log','R',32767);
    LOOP
    BEGIN
    UTL_FILE.get_line(v_filelog,v_logline);
    if v_logline = v_search then
    dbms_output.put_line(v_logline);
    end if;
    UTL_FILE.fclose(v_filelog);
    dbms_output.put_line('Closed File ' || v_sec.f_name|| '.log');
    exit;
    END;
    END LOOP;
    else
    dbms_output.put_line('File not found' || v_sec.f_name);
    END IF;
    END IF;
    END LOOP;
    --close the curosr .. check this
    EXCEPTION
    WHEN UTL_FILE.ACCESS_DENIED THEN
    DBMS_OUTPUT.PUT_LINE('No Access!!!');
    when others then
    dbms_output.put_line('ERROR (open_file) => '||sqlcode);
    dbms_output.put_line('MSG (open_file) => '||sqlerrm);
    end;

    Hi,
    You might have better luck in the PL/SQL or Java forums. They are located here:
    PL/SQL: PL/SQL
    Java: http://forums.oracle.com/forums/forum.jsp?forum=99
    Good luck,
    Mark

Maybe you are looking for