#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    How to command line options to a perl script from a different perl script


    How can i pass multiple command options to a perl script from a different script and to capture the output of that perl command, here is the snap shot i am trying

    @output `c:/test.pl' -c1 value1 -c2 value2 -c3 value3....

    where c1,c2,c3 are command line options for test.pl and value1,value2,value3... are values for each command option, but i am encountered with some compiler error's.

    Can someone please help me on this.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Location
    Paris area, France
    Posts
    842
    Rep Power
    496
    Did you try simply:

    @output = `c:/test.pl -c1 $value1 -c2 $value2 -c3 $value3`;

    I think it should probably work (although I can't test as I don't currently have Perl under Windows).
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    929
    Post the exact code you're trying (in between [code]...[/code] tags) and the errors you get.

    If you don't have the file associations set to make perl files executable, you will have to add the perl interpreter to laurent's answer:

    Code:
    # $^X gives the path of the perl.exe running the script
    @output = `$^X c:\test.pl -c1 value1 ...`;
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    5
    Rep Power
    0

    Thanks for the reply, it worked to me now...


    I am having another issue now, i am trying to send emails using Perl, currently my company is using LotusNotes and LDAP as a protocol..., i am getting an error "Unknown Server name"

    here is the code i am using

    #!/usr/bin/perl

    use MIME::Lite;

    # Set this variable to your smtp server name
    my $ServerName = "mail.servername";

    my $from_address = 'mycompany@test.com';
    my $to_address = 'myname@test.com';
    my $subject = 'MIME Test: Text';
    my $mime_type = 'text';
    my $message_body = "Testing text in email.\n";

    # Create the initial text of the message
    my $mime_msg = MIME::Lite->new(
    From => $from_address,
    To => $to_address,
    Subject => $subject,
    Type => $mime_type,
    Data => $message_body
    )
    or die "Error creating MIME body: $!\n";


    # Attach the text file
    my $filename = 'C:\test.txt';
    my $recommended_filename = 'test.txt';
    $mime_msg->attach(
    Type => 'application/text',
    Path => $filename,
    Filename => $recommended_filename
    )
    or die "Error attaching text file: $!\n";

    # encode body of message as a string so that we can pass it to

    Net::SMTP.
    my $message_body = $mime_msg->body_as_string();

    # Let MIME::Lite handle the Net::SMTP details
    MIME::Lite->send('smtp', $ServerName);
    $mime_msg->send() or die "Error sending message: $!\n";


    error i am getting :

    Failed to connect to mail server: Invalid argument
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    11
    Rep Power
    0
    nubsauce here, couldnt just use "system perl myprogram -c1 -c2 -c3"?

    EDIT: i didnt see you were on a new issue now, my bad

IMN logo majestic logo threadwatch logo seochat tools logo