how to pass variables to perl script from php script
Hi,
Im using perl script from php. I wanted to pass parameters to perl script from php and also return value from perl script to php. I dont no how to do it, Please some one help me in solving this problem. Thanking you in Advance. |
Well, what type of values are you passing? Are they easily represented as command line arguments? Passing them back can be tricky unless it's a simple "return code" type value. If so, that should be moderately simple. You could also set environment variables if the types aren't complex.
|
Quote:
http://php.net And if you'd like detailed help, ask a detailed question. You say nothing about version/distro of Linux, post any of the code, or give any examples. |
I thank both TB0ne and nuwen52, for answering my thread.
Ill give an example, to make you people understand my problem. Here's a perl script, "test1.pl". Code:
print "Hello from perl! " Code:
<?php Quote:
My question is, Can I pass variables or parameters to the perl script above from php script and return result from the perl script to php script? If s, How can I do so. Thanking you In Advance. |
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
|
Thank you pixellany, and please help me in solving the problem.
|
You example looks very much like to one given in this tutorial. If you continue through the tutorial you should learn how to achieve what you want to do.
|
Thank you graemef, yes I have used that example. And in that whole site, I did not get how to return values from the perl script, which should be used in php.
This is my perl script Code:
#!/usr/bin/perl Code:
<?php Quote:
The value HASH(0x8e5d880) is being print just because of the line16 Code:
print $t,"\n"; Quote:
|
As the tutorial states you can use output buffering to capture as the output anything that is printed by the perl script. (example 2) You can establish a function and pass it values (example 6).
Try those out, see what you get. |
Thank you graemef, I solved the problem by using output buffer. I'm storing the output(values) of the perl script in the buffer, and using these values in the php script.
Thank you very much for showing concern on me. |
try printing the result within perl. Then using the output buffer technique capture the result in PHP
|
Thank you graemef. I'm using the same method. But I have another problem.
This is my perl script "code1.pl" Code:
#!/usr/bin/perl -w This is my PHP file, which i run via browser. Code:
<?php Quote:
Code:
shell_exec('perl code1.pl $User'); Quote:
But I wanted to pass by reference ie.,$User. |
If you use single quote then variables will not be expanded. Try using double quotes.
Code:
shell_exec("perl code1.pl $User"); |
Thank you graemef.
IT WORKED. Thanks a lot...... |
Hi,
Im back with another problem. I'm Using this HTML file, "adduser.html" Code:
<html> Code:
<?php Code:
#!/usr/bin/perl -w And the problem I'm facing is, I'm able to pass the values from html to php and from php to perl intern, but the Control is not passing into the perl script at line 98 and beyond. But, if run the same php script from command prompt, the control is being passed to the line 98 and beyond. Any solution would be appreciated. Thanking you in Advance. |
All times are GMT -5. The time now is 08:13 PM. |