Reputation: 49
I have the following php script which needs to call a perl script along with the arguments. If I have the paths correct, is there anything wrong with the syntax? The php and the perl on server side. The php receives information (the $GET['zipc'] thru a url. The perl script will produce an xml file back on the server. I keep getting unexpected 'exec' (T_STRING) on line 8. Thanks for any advice.
<?php
$zipc="-Z";
$lineup="-Y USA";
$fformat="-U";
$duration="-d 2";
$outfile="-o";
$ofile="guide.xml"
exec("perl http://www.myserver.com/myperl.pl" $zipc $_GET['zipc'] $lineup $fformat $duration $outfile "http://www.myserver.com/myfile.xml");
print"FINALLY GOT TO END";
?>
EDIT: Well I thought it was all worked out. Now I get the following error: Fatal error: Only variables can be passed
According to the tech support people where I have the scripted hosted, I have to rewrite the line of code that contains the exec so as not to open connections. Kinda at loss on this one. Any advice?
EDIT 2: The problem lies in the array. From what I understand an array can not be passed as shown in the answer without generating an error. To fix the problem I concatenate the variable and the $_GET into one variable. Seemed to fix the problem.
Upvotes: 0
Views: 89
Reputation: 1923
The second argument to the exec() function is an array. You have multiple syntax errors in your code because you have simply listed a bunch of variables without putting them inside of an array.
Even if exec()
did take a long list of parameters, which it doesn't, your code would still not work because you didn't separate them with commas.
This should work (note the changes on lines 7 & 8):
<?php
$zipc="-Z";
$lineup="-Y USA";
$fformat="-U";
$duration="-d 2";
$outfile="-o";
$ofile="guide.xml";
exec("perl http://www.myserver.com/myperl.pl", array($zipc, $_GET['zipc'], $lineup, $fformat, $duration, $outfile, "http://www.myserver.com/myfile.xml"));
print"FINALLY GOT TO END";
Upvotes: 1