Can not pass data to perl file

Hey,

I can not pass form data to perl file. Without Yii, no problem to get data from php file to perl. Following code is working without Yii. Here is my code

test.php

<FORM action="<?php echo APP_URL; ?>/test/retrieve" method="POST">

First Name: <input type="text" name="first_name"> <br>

Last Name: <input type="text" name="last_name">

<input type="submit" value="Submit">

</FORM>

<?php

$output = shell_exec(’/var/www/test/cgi-bin/retrieve.pl’);

echo "<pre>$output</pre>";

?>

retrieve.pl

#!/usr/local/bin/perl

local (&#036;buffer, @pairs, &#036;pair, &#036;name, &#036;value, %FORM);


# Read in text


&#036;ENV{'REQUEST_METHOD'} =~ tr/a-z/A-Z/;


if (&#036;ENV{'REQUEST_METHOD'} eq &quot;POST&quot;)


{


    read(STDIN, &#036;buffer, &#036;ENV{'CONTENT_LENGTH'});


}else {


&#036;buffer = &#036;ENV{'QUERY_STRING'};


}


# Split information into name/value pairs


@pairs = split(/&amp;/, &#036;buffer);


foreach &#036;pair (@pairs)


{


(&#036;name, &#036;value) = split(/=/, &#036;pair);


&#036;value =~ tr/+/ /;


&#036;value =~ s/%(..)/pack(&quot;C&quot;, hex(&#036;1))/eg;


&#036;FORM{&#036;name} = &#036;value;


}


&#036;first_name = &#036;FORM{first_name};


&#036;last_name  = &#036;FORM{last_name};

print "Content-type:text/html\r\n\r\n";

print "<html>";

print "<head>";

print "<title>Hello - Second CGI Program</title>";

print "</head>";

print "<body>";

print "<h2>Hello $first_name $last_name - Second CGI Program</h2>";

print "</body>";

print "</html>";

1;

Can anyone help me where is the problem?

Did you try one of these?




echo "<pre>{$output}</pre>";

echo '<pre>'.$output.'</pre>';



Edit:

Forget that! I misunderstood the double quote semantics in PHP. :rolleyes:

Edit2:

My best guess is that it’s a result of this line in yiic.php




defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));



Edit3:

I was wrong again (btw, yiic of course is the command line script). It was stupid of me trying to answer this one.

Edit4:

Now I’m really confused. Is this at all possible? Seems like two cooperating perl scripts was involved from the beginning. I believe shell_exec spawns a subprocess. What about the environment. A subprocess havs a copy, doesn’t it? Obviously perl complains about $ENV being uninitialized. Also, wouldn’t this be dependent on register_globals=on?

/Tommy

Still no luck to get data from perl. Can any one help me?

test.php

<FORM action="<?php echo APP_URL; ?>/test/retrieve" method="POST">

First Name: <input type="text" name="first_name"> <br>

Last Name: <input type="text" name="last_name">

<input type="submit" value="Submit">

</FORM>

<?php

$output = shell_exec(’/var/www/test/cgi-bin/retrieve.pl’);

echo "<pre>$output</pre>";

?>

[b]

retrieve.pl[/b]

#!/usr/local/bin/perl

local ($buffer, @pairs, $pair, $name, $value, %FORM);

Read in text

$ENV{‘REQUEST_METHOD’} =~ tr/a-z/A-Z/;

if ($ENV{‘REQUEST_METHOD’} eq “POST”)

{

read(STDIN, $buffer, $ENV{‘CONTENT_LENGTH’});

}else {

$buffer = $ENV{‘QUERY_STRING’};

}

Split information into name/value pairs

@pairs = split(/&/, $buffer);

foreach $pair (@pairs)

{

($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;

$value =~ s/%(…)/pack("C", hex($1))/eg;

$FORM{$name} = $value;

}

$first_name = $FORM{first_name};

$last_name = $FORM{last_name};

print "Content-type:text/html\r\n\r\n";

print "<html>";

print "<head>";

print "<title>Hello - Second CGI Program</title>";

print "</head>";

print "<body>";

print "<h2>Hello $first_name $last_name - Second CGI Program</h2>";

print "</body>";

print "</html>";

1;

Are you sure you had this working in php (outside of Yii)?

I can’t figure out how to pass the request params and the form using shell_exec.

The only thing that makes sense to me is if the functionality of "test.php" was in a CGI script, and you included "retrieve.pl". In one of your previous threads in this forum you suggested inclusion of "test.pl".

/Tommy

Hi Tommy,

That was my fault, and typo. this is the original files. I can pass value to perl file but in yii I can not pass file. DO I need to change any thing? Let me know.

Neel

test.php

<FORM action="cgi-bin/retrieve.pl" method="POST">

First Name: <input type="text" name="first_name"> <br>

Last Name: <input type="text" name="last_name">

<input type="submit" value="Submit">

</FORM>

retrieve.pl

#!/usr/local/bin/perl

local ($buffer, @pairs, $pair, $name, $value, %FORM);

Read in text

$ENV{‘REQUEST_METHOD’} =~ tr/a-z/A-Z/;

if ($ENV{‘REQUEST_METHOD’} eq “POST”)

{

read(STDIN, $buffer, $ENV{‘CONTENT_LENGTH’});

}else {

$buffer = $ENV{‘QUERY_STRING’};

}

Split information into name/value pairs

@pairs = split(/&/, $buffer);

foreach $pair (@pairs)

{

($name, $value) = split(/=/, $pair);

$value =~ tr/+/ /;

$value =~ s/%(…)/pack("C", hex($1))/eg;

$FORM{$name} = $value;

}

$first_name = $FORM{first_name};

$last_name = $FORM{last_name};

print "Content-type:text/html\r\n\r\n";

print "<html>";

print "<head>";

print "<title>Hello - Second CGI Program</title>";

print "</head>";

print "<body>";

print "<h2>Hello $first_name $last_name - Second CGI Program</h2>";

print "</body>";

print "</html>";

1;

0