Amateur with perl script

Trying to use the small perl script referred to in the message down below to send mail from the command line using unix mail. Any advice about what the error message immediately below refers to will be appreciated.
"smtp.mac.com" is not exported by the Net::SMTP module
Can't continue after import errors at myprogram.pl line 5
BEGIN failed--compilation aborted at myprogram.pl line 5.
Bill, below is a good example of how to do it with the perl script method. I use my verizon smtp server (outgoing.verizon.net) to send the mail. I haven't been able to use the postfix server on my own Mac to do it. Maybe someone can help us learn how to do that.
http://members.toast.net/strycher/perl/examplenetsmtp.htm
Boyd

I suggest that you find a better
source of information. I was finally able to make the
date_r method work in this example but I had to write
my own tz_offset function.
I agree, I'd find a better example somewhere. Looking at that page, I'm fairly certain that those examples are simply taken out of much larger scripts without regard to whether they'd actually run as written.
And the date_r subroutine is just plain odd, if you ask me. I'm not sure why he'd go to the trouble of writing it like that when he could do it with two lines of code. Unless he can't use POSIX on Windows...
First, he'd just have to add
<pre class="command">use POSIX qw(strftime);</pre>to the top of his script, then he could get the date/time formatted more or less like he had it with this:
<pre class="command">my $date = strftime("%A, %e %B %Y %T %z", localtime(time));</pre>I'm not sure about the time zone offset being "-500" and not "-0500", which is more what I'm used to seeing.
This page has a more straightforward explanation and example of how to use Net::SMTP. Just go through it down to just before "Other Neat Stuff with Net::SMTP."
charlie

Similar Messages

  • Best method for timestamping? (for later use with perl script)

    What is the best method that I can use to timestamp events in Linux for later use with perl script?
    I am performing some energy measurements.. where I am running several tasks separated by 20 secs in between. Before I start any execution of tasks, I always place initial delay for me to start the script and start the measurement device.
    My problem is that I don't know how long is that first delay exactly. So to solve this, I thought I could use date commands to time stamp all tasks.. or at least to timestamp first dela.
    Here is example of what I am doing:
    1st delay
    task 1
    20s
    task 2
    20s
    task 3..... etc
    What would be the best to use?

    logger.
    It posts messages straight to the system log.  You can see the message, in all its glory using tools like journalctl.  You will see the message, the date, time, host name, user name, and the PID of logger when it ran.

  • Java with Perl scripts

    Hello,
    I would like to have my applet use a perl script. How do I embed a perl script in Java? Is there a special library? Thanks.
    [email protected]

    You could probably just use Runtime.exec() to execute the script on the server.
    - Sheepy

  • Illegal character '%' at position 1 - need help with perl script!

    iTunes U Access Debugging
    Received
    Destination kean.edu
    Identity %22Jack Black%22 %3C%28jblack%29.%40kean.edu%3E %28jblack%29 %5B42%5D
    Credentials STUDENT%40urn%3Amace%3Aitunesu.com%3Asites%3Akean.edu
    Time 1178737992
    Signature 8786768fc3ebf9d3faf404a42bdb8a8d14c481e270fb75f084ebdd815553e1e4
    Analysis
    The destination string is valid and the corresponding destination item was found.
    The identity string is invalid: Illegal character '%' at position 1.
    The credential string is valid but contains no known credentials.
    The credential string contains the following credential which is not used within iTunes U:
    STUDENT%40urn%3Amace%3Aitunesu.com%3Asites%3Akean.edu
    The time string is valid and corresponds to 2007-05-09 19:13:12Z.
    The signature string is valid.
    Access
    Because the received signature and time were valid, the received identity and credentials were accepted by iTunes U.
    In addition, the following 2 credentials were automatically added by iTunes U:
    All@urn:mace:itunesu.com:sites:kean.edu
    Authenticated@urn:mace:itunesu.com:sites:kean.edu
    With these credentials, you have browsing and downloading access to the requested destination.

    Ken
    Thanks for lookiing into the issue.
    I am using the perl file downloaded from the iTunesU website.
    Here is the script:
    the only thing i replaced in this script is the shared secret, debug suffix, display name, email address and username with appropriate ones.
    use strict;
    use Digest::SHA qw(hmacsha256hex);
    use URI::Escape;
    use LWP::UserAgent;
    use Encode qw(encode);
    # to redirect errors to the browser
    use CGI::Carp qw(fatalsToBrowser);
    # to allow inputs from website using CGI scripting
    use CGI qw(:standard);
    sub main() {
    # Define your site's information. Replace these
    # values with ones appropriate for your site.
    my $siteURL = "https://deimos.apple.com/WebObjects/Core.woa/Browse/kean.edu";
    my $debugSuffix = "/abc123";
    my $sharedSecret = "YOURSHAREDSECRETKEYCODE";
    my $administratorCredential = "Administrator\@urn:mace:itunesu.com:sites:kean.edu";
    # Define the user information. Replace the credentials with the
    # credentials you want to grant to that user, and the optional
    # identity information with the identity of the current user.
    # For initial testing and site setup, use the singe administrator
    # credential defined when your iTunes U site was created. Once
    # you have access to your iTunes U site, you will be able to define
    # additional credentials and the iTunes U access they provide.
    my @credentialArray = ($administratorCredential);
    my $displayName = "Michael Searson";
    my $emailAddress = "msearson\@kean.edu";
    my $username = "msearson";
    my $userIdentifier = "42";
    # Append your site's debug suffix to the destination if you
    # want to receive an HTML page providing information about
    # the transmission of credentials and identity between this
    # program and iTunes U. Remove this code after initial
    # testing to instead receive the destination page requested.
    # uncomment the line below to access debug information from the
    # iTunes U server.
    $siteURL .= $debugSuffix;
    # Ready this data for transfer, the order must be correct!
    my $identity = getIdentityString($displayName, $emailAddress, $username, $userIdentifier);
    # turn the array of credentials into a semicolon delimited string
    my $credentials = getCredentialsString(@credentialArray);
    # time that this key is generated. The key is valid for 90 seconds.
    my $currentTime = time;
    my %token = getAuthorizationToken($identity, $credentials, $currentTime, $sharedSecret);
    invokeAction($siteURL, %token)
    sub getIdentityString()
    # Combine user identity information into an appropriately formatted string.
    # take the arguments passed into the function copy them to variables
    my ($displayName, $emailAddress, $username, $userIdentifier) = @_;
    # wrap the elements into the required delimiters.
    my $returnValue = sprintf('"%s" <%s> (%s) [%s]', $displayName,
    $emailAddress, $username, $userIdentifier);
    return $returnValue;
    sub getCredentialsString()
    # this is equivalent to join(';', @_); this function is present
    # for consistency with the Java example.
    # concatenates all the passed in credentials into a string
    # with a semicolon delimiting the credentials in the string.
    #make sure that at least one credential is passed in
    my $returnValue = "";
    my $credentialCount = @_;
    if ($credentialCount > 0) {
    for (my $i=0; $i < $credentialCount; $i++) {
    if ($i == 0) {
    $returnValue = sprintf('%s', $_[$i]);
    } else {
    $returnValue = sprintf('%s;%s', $returnValue, $_[$i]);
    } else {
    die "credentialArray must have at least one credential";
    return $returnValue;
    sub getAuthorizationToken()
    # Create a buffer with which to generate the authorization token.
    my ($identity, $credentials, $expriation, $key) = @_;
    my $signature;
    my $buffer;
    my %token_hash = ();
    my $escapedUTF8EncodedCredentials = uri_escape(encode("UTF-8", $credentials), "^A-Za-z0-9\-_.* ");
    my $escapedUTF8EncodedIdentity = uri_escape(encode("UTF-8", $identity), "^A-Za-z0-9\-_.* ");
    my $escapedUTF8EncodedExpiration = uri_escape(encode("UTF-8", $expriation), "^A-Za-z0-9\-_.* ");
    # create the POST Content and sign it
    $buffer .= "credentials=" . $escapedUTF8EncodedCredentials;
    $buffer .= "&identity=" . $escapedUTF8EncodedIdentity;
    $buffer .= "&time=" . $escapedUTF8EncodedExpiration;
    # This is necessary because uri_escape does encode spaces to pluses.
    $buffer =~ s/[ ]/+/g;
    # returns a signed message that is sent to the server
    $signature = hmacsha256hex($buffer, $key);
    $token_hash{'credentials'} = $escapedUTF8EncodedCredentials;
    $token_hash{'identity'} = $escapedUTF8EncodedIdentity;
    $token_hash{'time'} = $escapedUTF8EncodedExpiration;
    $token_hash{'signature'} = $signature;
    # append the signature to the POST content
    return %token_hash
    sub invokeAction()
    # Send a request to iTunes U and record the response.
    # Net:HTTPS is used to get better control of the encoding of the POST data
    # as HTTP::Request::Common does not encode parentheses and Java's URLEncoder
    # does.
    my ($siteURL, %token) = @_;
    #print "$token\n";
    my $ua = LWP::UserAgent->new;
    my $response = $ua->post($siteURL, \%token);
    print "Content-type: text/html\n\n";
    print $response->content;
    main();
    AND HERE IS THE OUTPUT
    Received
    Destination kean.edu
    Identity %22Michael Searson%22 %3Cmsearson%40kean.edu%3E %28msearson%29 %5B42%5D
    Credentials Administrator%40urn%3Amace%3Aitunesu.com%3Asites%3Akean.edu
    Time 1178819683
    Signature 4d012f2cb6e465dbc4ae41b4905ad3c334c695e36b06e9ae406acf02f25387d1
    Analysis
    The destination string is valid and the corresponding destination item was found.
    The identity string is invalid: Illegal character '%' at position 1.
    The credential string is valid but contains no known credentials.
    The credential string contains the following credential which is not used within iTunes U:
    Administrator%40urn%3Amace%3Aitunesu.com%3Asites%3Akean.edu
    The time string is valid and corresponds to 2007-05-10 17:54:43Z.
    The signature string is valid.
    Access
    Because the received signature and time were valid, the received identity and credentials were accepted by iTunes U.
    In addition, the following 2 credentials were automatically added by iTunes U:
    All@urn:mace:itunesu.com:sites:kean.edu
    Authenticated@urn:mace:itunesu.com:sites:kean.edu
    With these credentials, you have browsing, downloading, uploading, and editing access to the requested destination.

  • Perl-script  Net::SMTP and iMS. How To? :(

    How to configure iMS to send mail with Perl-script using Net::SMTP module?
    Script and iMS must run in different hosts.

    Thats more a topic for perl and smtp than it is for IMS. Anyway, you could do:
    unshift @{$Mail::Sendmail::mailcfg{'smtp'}} , 'mailserver.host.com';
    %mail = (
              To => '[email protected]',
    From => '[email protected]',
    Message => 'this is my message!,
              Subject => 'Test Subject',
    sendmail(%mail) or die "Mail Not Sent!";

  • Perl script to delete attributes with space value

    Hi,
    We are using Iplanet Ldap Directory server on hp-UX 11i.
    I have a problem here with the attribute values.There is a space (a blank space) for few attributes across the directory server.
    They seem to be normal when lokked through the ldap console. But when retrieving data through ldapsearch utility they appear as Junk character.
    The only solution for this may be find and delete those attributes and add new one's.
    eg: telephoneNumber :: RASWD== ( when the attribute has one space value,nothing else)
    My issue is iam not able to trace the attributes through perl ldap scripts.
    If anyone can help me out with a script it would be great.There are few thousand employees data appear corrupted.
    Thanks in advance.

    This is how SunOne avoids storing lots of extra spaces (and thus using disk/memory) It base 64 encodes the entries. I believe you can use the -B flag to ldapsearch to display the entry as it really appears not encoded.
    If you really wanted to ideantify them I would write a perl script to locate attribute:: in a db2ldif of the install.
    That would at least tell you which ones have the issue with spaces

  • I have perl scripts that I want to be able to run with my iplanet web server 6.0. How can I make it work in Windows NT? (Because I have no problem when I use it with Linux).

     

    Hi Melanie,
    In order to run a PERL script under Windows NT the iPlanet Web Server needs to know where to find the PERL interpreter.
    follow these steps :
    1) Make sure Windows NT knows what a .pl file is. In file Manager click on file and choose associate from the menu. Check the "files with extension" drop-down list for pl - if it exists verify that it is pathed to your perl.exe. If it is not already on the list click the "New Type" button. In the Filetype box put pl. Choose open from the Action drop-down list. In the Command box specify the full path to your perl.exe interpreter (Make sure to use short filenames, rather than long filenames.) Click the OK button. Then click the Close button in the main Associate dialog box. Double click a .pl file to test - it should automatically launch the PERL interpreter and feed it your .pl file.
    2) Create a directory to contain your .pl scripts.
    ~server_root\shell-cgi is a good choice.
    or \cgi-bin\
    NOTE: Make very sure that this directory is NOT part of the document root, it should have it's own directory (preferably at the same level of the docroot).
    3) In the Admin Server select Programs.
    4) Choose CGI directory (normally) or WinCGI directory or ShellCGI Directory depending on ur choice from the Programs menu.
    5) Put the URL Prefix you would like to map to your Shell-CGI directory into the URL Prefix field.
    6) Put the full path to your Shell-CGI directory in the Shell CGI directory field.
    7) Click OK.
    8) The save and apply changes page will display your changes and give you the opportunity to verify them. If they are correct click the Save and Apply button. If not Click the Undo button and go back to step 4.
    (9)You can then call your .pl scripts directly by referencing the directory mapping that you have just created. For example:
    http://my.server.whatever/shell-cgi/ myscript.pl
    this should work now.
    If not Pls Mail me.
    regards
    T.Raghulan
    [email protected]

  • Capture output of Perl script with jsp:include

    The company's main web site has a CGI script written in Perl that generates a header, and another one that generates a footer. I would like to deploy a JSP that incorporates the header and footer without having to re-implement the header/footer Perl code in Java.
    Can the <jsp:include> tag include the output from these Perl scripts?

    Well, I tried it. The answer seems to be no.
    I created a simple CGI hello-world thingie and tested it, works fine from a browser (I'm doing all this remotely on a friend's Gentoo box so I know it's not just cached in my browser or anything).
    Then I created a simple JSP and used a fully-qualified URL pointing to the executable CGI script. While the JSP compiles and renders (I had some text in the JSP itself too), the part where it's supposed to include the content of the Perl script doesn't even appear.
    I also tried putting the CGI script into my webapp directory and specifying a relative path to the script, and it doesn't seem to get executed either. To confirm that I'm doing everything right, I put together a simple HTML file that has the same output and changed the "page" attribute to point to that file instead. Sure enough, the output appears.
    So the answer to my question appears to be: no, the output of a Perl CGI cannot be included into a JSP with the <jsp:include> tag. But I'm going to double-check on the Tomcat-user mailing list.

  • Folder Action to Launch Perl Script

    Hello.
    I wrote a perl script which I wanted to execute when a file was dropped into a folder. I added a folder action with a very simple applescript:
    on adding folder items to this_folder after receiving added_items
    do shell script ¬
    ("perl /Users/Alexander/Library/Scripts/gte2.pl")
    end adding folder items to
    The folder action didn't do anything, any thoughts on what I'm doing wrong? Note, the perl script works fine when I run it from the terminal.
    thanks.

    Thanks Camelot, I appreciate the help. My script below is trying to read data from a file in folder in my system. So I will try your suggestion, I didn't realize the environment and path my be different.
    Regards Alex
    #!/usr/bin/perl -w
    #This program is to convert files from gamin running GPS watch to text file which can be loaded into excel.
    # To make executable, remember to set: chmod u+x <file>
    #set all the flags. Note the flags are used to stop the matching
    $i = 1; $k = 0; $start = "no";
    #Open data file and find values
    open(DATA,"/Users/Alexander/Alex's Misc/Health/Garmin_Conversion/run.tcx") || die "Couldn't open file*\n";
    #read in the data line by line until "end of file"
    while (<DATA>){
    #start parsing for information to keep
    if (/.<Id>./) {
    @Idline=split(/>/);
    @Idbeat=split(/T/,$Idline[1]);
    $Id=$Idbeat[0];
    if (/.<Track>./){
    $start = "yes";
    if ($start eq "yes"){
    if (/.<Time>./) {
    @timeline=split(/T/);
    @timebeat=split(/Z/,$timeline[2]);
    $Time[$i]=$timebeat[0];
    elsif (/.<LatitudeDegrees>./) {
    @HRline=split(/>/);
    @HRbeat=split(/</,$HRline[1]);
    $Latitude[$i]=$latbeat[0];
    elsif (/.<LongitudeDegrees>./) {
    @longline=split(/>/);
    @longbeat=split(/</,$longline[1]);
    $Longitude[$i]=$longbeat[0];
    elsif (/.<AltitudeMeters>./) {
    @altline=split(/>/);
    @altbeat=split(/</,$altline[1]);
    $Altitude[$i]=$altbeat[0];
    elsif (/.<DistanceMeters>./) {
    @distline=split(/>/);
    @distbeat=split(/</,$distline[1]);
    $Distance[$i]=$distbeat[0];
    elsif (/.<Value>./) {
    @HRline=split(/>/);
    @HRbeat=split(/</,$HRline[1]);
    $HR[$i]=$HRbeat[0];
    $i++;
    } #string matching
    } #if start flag is yes
    } #while data loop
    close (DATA) || die "couldn't close file.\n";
    #write all data to file in space delimited format
    open (NEWFILE, ">/Users/Alexander/Alex's Misc/Health/Garmin_Converted/$Id run") || die "can't create file.\n";
    $Time[0]="Time"; $Latitude[0]="Latitude"; $Longitude[0]="Longitude"; $Altitude[0]="Altitude"; $Distance[0]="Distance"; $HR[0]="HR";
    print NEWFILE "0 $Time[0] $Latitude[0] $Longitude[0] $Altitude[0] $Distance[0] $HR[0]\n";
    for ($j = 1; $j <= $i; $j++) {
    $k=$j+1;
    print NEWFILE "$j $Time[$j] $Latitude[$j] $Longitude[$j] $Altitude[$j] $Distance[$j] $HR[$j]\n";
    } #for j loop
    close (NEWFILE) || die "couldn't close newfile.\n";
    #This is the end of the program

  • How to launching a perl script by the "begin" script of a jumpstart

    Hi all,
    i have an urgent pb with my solaris jumpstart, let me explain to you :
    i want that the begin script launch some perl script, but i have a problem
    here is my "begin" script:
    echo "Begining ISO FLAR based jumpstart."
    echo ""
    echo "Starting Ullink Configuration"
    env > /tmp/env
    /bin/sh << EOF
    /usr/bin/perl /cdrom/.archives/admin-scripts/sethostname.pl
    EOFmy perl script use a STDIN
    with this configuration, the perl script is launching but it runs in a loop indefinitely with an error "use of uninitialized value", because (i think) a value is return to the begin scritp and not to the perl script.
    well, on a pre-installed solaris, if a launch the begin script, it happens the same thing, it runs in a loop, BUT if i comment the line "/bin/sh <<EOF" and "EOF", it works.
    at this step, i say "ok it's cool my script is working", but when i use it during the jumpstart instalaltion, the perl script does not start, without any particular error.
    here is my perl script, if you want to test :
    #!/usr/bin/perl -w^M
    # Set Hostname for Ullink Jumpstart^M
    ^M
    use strict;^M
    ^M
    sub hit_enter {^M
        print "Hit enter to continue\n";^M
        <STDIN>;^M
        print "\033[2J";^M
    }^M
    ^M
    sub get_hostname {^M
        my %towns_list = (^M
            'Paris' => 'PA',^M
            'New-York' => 'NY',^M
        );^M
    ^M
        my %sites_list = (^M
            'Office' => 'OFC',^M
            'Redbus' => 'RED',^M
            'Telehouse' => 'TLH',^M
            'DTC' => 'DTC',^M
            'iAdvantage' => 'IAD',^M
            'Nutley' => 'NUT',^M
            'Level3' => 'LV3',^M
            'Equinix' => 'EQX',^M
            'Tata' => 'TAT',^M
            'Switch-data' => 'SWI',^M
            );^M
    ^M
        my %usage_list = (^M
            'Production' => 'PRD',^M
            'UAT' => 'UAT',^M
            'DMZ' => 'DMZ',^M
        );^M
    ^M
        sub select_list {^M
            my $counter=-1;^M
            my %hash_list = @_;^M
            my @keys = keys %hash_list;^M
    ^M
            # Clear screen^M
            print "\033[2J";^M
            print "In which country this machine is hosted or will be host and will be used ?\n\n";^M
    ^M
            # Get all keys from hash^M
            my $key;
            while ($key = each %hash_list ) {^M
                $counter++;^M
                print "$counter - $key\n";^M
            }^M
    ^M
            print "\nChoose the number corresponding to your choice :\n";^M
            my $choice_number;
            chomp ($choice_number = <STDIN>);^M
    ^M
            # Verify answer^M
            if (($choice_number =~ /\d+/) and ($choice_number <= $counter)) {^M
                # Add choice to chosen hostname^M
                my $chosen=$hash_list{$keys[$choice_number]};^M
                return $chosen;^M
            } else {^M
                print "\nYour answer is not correct, you need to enter a number between 0 and $counter\n";^M
                &hit_enter;^M
                &select_list;^M
            }^M
        }^M
    ^M
        sub srv_number {^M
            print "\033[2J";^M
            print "What is the server number ?\n";^M
            my $server_number;
            chomp ($server_number = <STDIN>);^M
            if ($server_number =~ /\d+/) {^M
                return $server_number;^M
            } else {^M
                print "\nYour answer is not correct, you need to enter a number\n";^M
                &hit_enter;^M
                &srv_number;^M
            }^M
        }^M
    ^M
        my $full_hostname = &select_list(%towns_list).'-';^M
        $full_hostname = $full_hostname.&select_list(%sites_list).'-';^M
        $full_hostname = $full_hostname.'SRV-';^M
        $full_hostname = $full_hostname.&select_list(%usage_list).'-';^M
        $full_hostname = $full_hostname.&srv_number;^M
    ^M
        sub write_hostname2tmp {^M
            open (HOSTNAME, ">/tmp/set_hostname") or warn "Couldn't write $_[0] to temp file : $!\n";^M
                print HOSTNAME "$_[0]\n";^M
            close (HOSTNAME);^M
        }^M
    ^M
        print "\033[2J";^M
        print "Is $full_hostname the correct name for this server ? (y/n)\n";^M
        if (<STDIN> =~ /y|yes/i) {^M
            &write_hostname2tmp($full_hostname);^M
        } else {^M
            print "Would you like to retry (r) or set manually the hostname (s) ? (r/s)\n";^M
            if (<STDIN> =~ /s/i) {^M
                print "Type the full required name and hit enter when finished :\n";^M
                chomp ($full_hostname = <STDIN>);^M
                &write_hostname2tmp;^M
            } else {^M
                &get_hostname;^M
            }^M
        }^M
    }^M
    ^M
    # Start configuration^M
    print "\033[2J";^M
    print "\n########################################################\n";^M
    print "#\t\t\t\t\t\t       #\n";^M
    print "#\t\t\tULLINK\t\t\t       #\n";^M
    print '#  Solaris Environnement Installation for Datacenters  #';^M
    print "\n#\t\t\t\t\t\t       #";^M
    print "\n########################################################\n\n";^M
    print "Before starting installation, you need to enter a set of informations.\n(answer to all questions, you can Ctrl+C to stop now)\n\n";^M
    &hit_enter;^M
    ^M
    &get_hostname;^Mthank for your help
    Edited by: ullink on Jun 25, 2009 6:05 AM

    Hi Manju,
    You can try the following command and check if any helps:
    Get-Exchangeserver |where-object{$_.AdminDisplayVersion -like "Version 15*"} |Get-MailboxStatistics | Ft -auto -wrap DisplayName,database,servername,*size*,*time*
    Best regards,
    Niko Cheng
    TechNet Community Support

  • Runtime.exec("Perl Script writing and reading on I/O"), handling Streams

    Hi all !!
    In a first place : sorry for my english if it's not really understandable but I try to do as good as possible !
    I'm writing a GUI with Swing that will allow (in one of my multiple tables) the user to run a Perl Script.
    This Perl Script ask the user to choose a Folder ... then read all the files in this folder and for each file (xml File), extract the datas and put them in a database. But when a file that has to be inserted in the database contains this line : <Template_Used name="ST1.mtt"> and if the Template table in my database doesn't have the "ST1.mtt" stored ... the Perl Script ask to the user to give him the path of the file "ST1.mtt" so that the script can put the "ST1.mtt template" datas in the database.
    This script runs well when it is from a windows console.
    But I need a graphic interface !!!
    So I created a JButton "Process a folder".
    When the button is pressed, a JFileChooser appears and ask the user which Folder has to be processed.
    Then a Process is created with the command : ("cmd.exe /C \"C:\\Program Files\\Fluke\\Ansur\\ProcessFolder.bat\").
    The BatFile :
    {code}cd C:\Documents and Settings\tsd\Desktop\Gael-Project\Project_Files
    perl Process.pl
    exit{code}
    At this moment everything is working well.
    But my Process.pl (which is 300 lines long ... and that you don't even want to hear about), ask in a first time the Path of the folder to process and sometimes ask the path to a file (a template file).
    So I need to read and wirte on the STDIN/STDOUT during the exec of the Process.
    In order to handle this I created two different threads : one reading the Process.getInputStream with a BufferedReader and one other writing on the Process.getOutputStream with a PrintWrinter.
    What I need to do is :
    When I read a line from the InputStream saying "I need the path of the ST1.mtt file", I should run a JFileChooser ... the user find the file in the computer ... and I write in the OutputStream the path of the file, so that my Perl Script doesn't have un Unitialised value on <STDIN> and can continue to process !!
    I'm pretty sure it's possible ... because at the moment I just used a trick :
    When the user push the "process a folder" button, I write the paths in the OutputStream before than the script needs it and it works !
    But I need to write in the OutputStream only when it is time !!!
    Any idea ??
    Here are some parts of my code :
    {code}
    String filename = File.separator+"tmp";
              JFileChooser fc = new JFileChooser(new File(filename));
              fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY );
              // Show open dialog; this method does not return until the dialog is closed
         fc.showOpenDialog(null);
         Folder = fc.getSelectedFile();
              new GoodExec(cmd);
    {code}
    {code}
    public class GoodExec {
         public static Process proc;
         public static StreamGobbler errorGobbler;
         public static StreamGobbler inputGobbler;
         public static StreamGobbler outputGobbler;
         public GoodExec(String cmd)
         try
                   Runtime rt = Runtime.getRuntime();
              proc = rt.exec(cmd);
         // any error message?
         errorGobbler = new
         StreamGobbler(proc.getErrorStream(), "ERROR");
         // any input?
         inputGobbler = new
         StreamGobbler(proc.getInputStream(), "INPUT");
         // any output?
              outputGobbler = new
              StreamGobbler(proc.getOutputStream(), "OUTPUT");
         // kick them off
         errorGobbler.start();
         inputGobbler.start();
         outputGobbler.start();
         // any error???
         int exitVal = proc.waitFor();
         System.out.println("ExitValue: " + exitVal);
         } catch (Throwable t)
         t.printStackTrace();
    {code}
    {code}
    public class StreamGobbler implements Runnable
    InputStream is;
    OutputStream os;
    String type;
    Thread thread;
    public static String chaine;
    StreamGobbler(InputStream is, String type)
    this.is = is;
    this.os=null;
    this.type = type;
    StreamGobbler(OutputStream os, String type)
    this.os = os;
    this.is=null;
    this.type = type;
    public void start () {
         thread = new Thread(this);
         thread.start ();
    public void run()
    try
    if (is == null){
         PrintWriter toProgram = new PrintWriter(os);
         File FolderToProcess = ProcessFolder.Folder;
    String Folder = FolderToProcess.getPath();
    toProgram.write(Folder);
    toProgram.close();
    else {
         if (os == null){
         InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line=null;
    String comp = "Please enter the exact path of the directory that contains the files you want to process.";
    while ( (line = br.readLine()) != null){
         if (type.equals("INPUT")){
              chaine+=line+"\n";
         if (line.equals(comp)) {
              System.out.println("give directory");RUN A JFILECHOOSER AND GIVE THE DIRECTORY TO THE OUTPUTSTREAM
    System.out.println(type + ">" + line);
    is.close ();
    catch (IOException ioe){
         ioe.printStackTrace();
    {code}
    And here is an example of a simple perl script that could be used (it s a simple one !!) :
    {code}
    #!/usr/bin/perl -w
    use strict;
    print "Please enter the exact path of the directory that contains the files you want to process.\n";
    my $dir= <STDIN>;
    chomp ($dir);
    print "titallala $dir";
    if (the template of the file is not in the database){
    print "Please give me the template so that I can put it in the database";
    $dir= <STDIN>;
    chomp ($dir);
    {code}
    Thank you for your help ... if it's possible to help me !!
    Gael

    BalusC -- The line that gives me my NullPointerException is when I call the "DisplayProduct()" method. Its a dumb question, but with NetBeans how do I find out which reference could be null? I'm not very familiar with how NetBeans works with finding out how to debug. Any help you can give me would be greatly appreciated.The IDE is com-plete-ly irrelevant. It's all about the source code.
    Do you understand anyway when and why a NullPointerException is been thrown? It is a subclass of RuntimeException and those kind of exceptions are very trival and generally indicate an design/logic/thinking fault in your code.
    SomeObject someObject = null; // The someObject reference is null.
    someObject.doSomething(); // Invoking a reference which is null would throw NPE.

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

  • Problem with Perl Function

    Hello,
    My MacBook Pro is running on Mac OS X v 10.6.5 (Snow Leopard), and I was trying to run a perl script on the terminal. The script contains perl functions, such as chomp, split, next; however, the perl in my MacBook could not read (recognize) those functions. I checked the perl versions and found both 5.10.0 and 5.8.9 installed at /usr/bin/perl. Still, the perl functions are not working. Also, when I ran the command "perldoc perl", it returned "No documentation found for perl".
    So, the questions are:
    1. Is perl properly installed in my MacBook?
    2. If not, how can I install it properly since the perl comes with OS as default?
    3. Why the perl functions are not working?
    Any help will be much appreciated.
    dehalococcoides

    ... The script contains perl functions, such as chomp, split, next; however, the perl in my MacBook could not read (recognize) those functions. I checked the perl versions and found both 5.10.0 and 5.8.9 installed at /usr/bin/perl.
    How can you have 2 versions in the same file? /usr/bin/perl ???
    Still, the perl functions are not working. Also, when I ran the command "perldoc perl", it returned "No documentation found for perl".
    So, the questions are:
    1. Is perl properly installed in my MacBook?
    It should be. It is installed on all my Mac systems, and I've been known to write perl scripts using chomp, split, and next.
    2. If not, how can I install it properly since the perl comes with OS as default?
    As has been mentioned, perhaps you need to either to do a clean install (backing up first; maybe backing up twice).
    3. Why the perl functions are not working?
    Your system does not seem right. Have you been trying to install your own perl packages? Manually? Via MacPorts.org? Via Fink.sf.net? Have you been trying to set your own Perl environment variables, and got them wrong?
    The perl statements you want to use are core perl statements, and if you can invoke perl at all, they should work.

  • Calling stored procedure from Perl Script

    Need help with the syntax to call a stored procedure with an input paramter using Perl. The input paramter will be set within the perl script.

    there is an oracle module you can find on cpan
    http://cpan.org/modules/by-category/07_Database_Interfaces/Oracle
    of course, you could also use sqlplus binary, as you would do in shell
    hth

  • Perl Script in PLSQL

    When do we typically need to use external scripts like perl scripts while working in oracle?
    For file manipulation,perls split function would be better than pl/sql code ,however,performance wise which one is better?
    How many such scenarios are there where a perl is better to be used as opposed to pl/sql
    please advise

    That depends on where the data is. If it is outside Oracle then PL/SQL is not the best approach. The UTL_FILE I/O interface is primitive.
    If the data is inside Oracle, then PL/SQL is the best approach.
    One method to consider is loading the files to be processed by Perl, as CLOBs, into Oracle. And once in Oracle, use PL and SQL to process the contents.
    Performance wise, I expect pretty similar performance. It is unlikely that one would be significantly faster than the other in this case. Regular expressions are also supported in Oracle.
    There are however features and advantages on the Oracle side that you do not have on the o/s side with Perl. Concurrency controls. Transactions. How do you rollback changes made when in Perl? Code them - which can be complex. In PL/SQL, you simply use the rollback command. And save points are also supported.
    Other factors can include the availability of the file to other applications and web reporting systems, and security and backup.
    If the file resides outside Oracle and a web reporting system for example needs to show the file contents plus the structured data set parsed from the file... this gets hairy when Perl was used to load the structured into a database (easily accessible via web app layer) and the file still sits on the o/s (another method required by app layer to access file, another set of authentication and authorisation to deal with, etc).
    It is a lot easier if the file is a CLOB inside Oracle - as any application will use the database (single access method and point of access) to obtain both the structured data and the file's contents.
    Then there's also the issue of backups. If the file is a CLOB in the database, it is part of the backup and security mechanisms implemented on that database. No need to deal with it at o/s level and its complexities.
    Of course, I assume that these are requirements accompanying the need to process and parse the file. And that is the bottom line - the requirements should drive the decision of whether to use Perl or PL/SQL in such a case. It is not a mere matter of which one may perform better than the other (especially not when it cannot be shown that there will be a significant performance improvement).
    By the way - the above scenario is a real world one for us. And interestingly, we had more performance issues with the Perl code (huge knock on server resources) than doing the same inside Oracle using PL/SQL.

Maybe you are looking for