-1

i have written this program to pass a variable in the embedded perl script but it gives blank output :-( why it is not working. Please fix this problem.

the php script

<?php
$var1='high'; 
exec('C:/xampp/htdocs/WORK/hello.pl'.' '.EscapeShellArg("$var1"),$output);
echo ($output);
?>

the perl script

#!/usr/bin/perl -w

    $var1=<>; 

    print $var1;
user1083096
  • 167
  • 6
  • 18

3 Answers3

1

Because youre trying to send an array as a string... Youll have to serialize the array into a string that perl can deserialize, like JSON, XML, CSV, etc..

prodigitalson
  • 60,050
  • 10
  • 100
  • 114
  • 1
    No, because "$var1" becomes "Array" (raw command is like this: C:/xampp/htdocs/WORK/hello.pl "Array" ) and there should be the output anyway. Issues somewhere else – Vitaly Dyatlov May 29 '12 at 11:53
  • Thats true... kinda jumped the gun... regardless hes not going to get the result hes expecting, though he needs to get the var passing correct first. – prodigitalson May 29 '12 at 11:58
  • sorry, i m new to this field.... could you please tell me where is the problem actually.. – user1083096 May 29 '12 at 12:05
1

What about

 $var1 = shift;

rather than reading the value from standard input or argument files?

choroba
  • 231,213
  • 25
  • 204
  • 289
0

One reason is that EscapeShellArg expects the $arg parameter to be of type string, while, in your case, it's an array...

Mihai Todor
  • 8,014
  • 9
  • 49
  • 86
  • Actually at that point he should be sending the string representation of the array i think because hes got it in double quotes when he passes it... – prodigitalson May 29 '12 at 11:52
  • i changed "$var1" to '$var1' but its not working :( – user1083096 May 29 '12 at 12:10
  • Are you able to call the PERL script via command line? Does it produce the expected output? Could we get a sample of the parameters that you are using when calling the script and the output that it produces? – Mihai Todor May 29 '12 at 12:27
  • yes i m able to call the script and it does produces the output. i tried using the same script posted above and its printing "array" as the output. – user1083096 May 29 '12 at 12:34