1

I want to call a perl script as an external program in a PHP script, once the PHP script finished its run, it should send back the output to a html page. I tried using exec command to call the perl script but it dint work out. please help with this simple perl script, so that i can try using the same !

Perl script:

#!/usr/bin/perl -s

$var1 = 'high';

print $var1;

Thanks ahead of time !!

1
  • 1
    well exec or system is what you should be using...can you post what you tried and how it "didn't work out" ? Commented May 27, 2012 at 17:02

2 Answers 2

1

the output of commands called via exec will be stored in the output parameter that you give (hence why it's specified as by reference) either print out the contents of that array or use the passthru() function instead

references: http://www.php.net/manual/en/function.exec.php

http://www.php.net/manual/en/function.passthru.php

so just

passthru('/usr/bin/perl yourscript.pl');

instead of

exec('/usr/bin/perl yourscript.pl');
Sign up to request clarification or add additional context in comments.

Comments

0

I would suggest trying

exec ('path_to_your_script')

This will work for any shell executable or command call, whenever you want to execute it from your PHP script.

2 Comments

ya thanks a lot i gotit :) i have one more doubt, how can i pass a variable to the embedded script?
just the same way you would do it in a shell - in PHP script you form up a fulll string of the shell command with path to executable and all paramenters to be called and then use this string as a parameter of the exec() function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.