1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

calling php command line program from perl

Discussion in 'PHP' started by sjhonny, Mar 16, 2005.

Thread Status:
Not open for further replies.
  1. #1
    hi,
    i'm trying to call a php command-line program from a perl script (like so:
    open (PIPE,"/path/to/my_program.php $arg1 $arg2 |");
    )
    when i run this perl program myself, it works fine. however, when i call it
    from within another program, i get only the HTML header (content type:
    ....).
    (of course, the first line in my_program.php contains the -q option, and it
    works perfectly when i call it myself)
    i've experimented a bit, and found that the same output is produced even if
    i replace the previous command with this one:
    open (PIPE,"/usr/local/php5/bin/php -v |");
    anybody got any clue?
    thanks,
    Jhonny
     
    sjhonny, Mar 16, 2005 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,494
    Likes Received:
    4,457
    Best Answers:
    123
    Trophy Points:
    665
    #2
    not command line but if the script is in a public folder you can try

    #!/usr/local/bin/perl -w
    require LWP::UserAgent;
     
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
     
    my $response = $ua->get('http://www.mysite.com/cron.manager.php');
     
    if ($response->is_success) {
    print $response->content; # or whatever
    }
    else {
    die $response->status_line;
    }
    Code (markup):
    or
    #!/usr/local/bin/perl -w
     
    use LWP::Simple qw( get );
    use CGI;
     
    my $URL="http://www.mysite.com/cron.manager.php";
     
    LWP::Simple::getprint($URL);
    Code (markup):
     
    sarahk, Mar 17, 2005 IP
  3. llllprogrammerllll

    llllprogrammerllll Guest

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi sjhonny,

    Have you ever tried to print out all the output?

    open DATA, "/usr/local/bin/php some_code.php |" or die
    "Couldn't execute program: $!";

    my $output;

    while (defined($line = <DATA>)) {
    $output .= "$line";
    }

    close DATA;

    print $output;
     
    llllprogrammerllll, Apr 3, 2008 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,494
    Likes Received:
    4,457
    Best Answers:
    123
    Trophy Points:
    665
    #4
    3 years on, who knows what he's tried!!!
     
    sarahk, Apr 3, 2008 IP
Thread Status:
Not open for further replies.