Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-29-2007, 01:47 AM   #1
LQ Newbie
Registered: Apr 2006
Posts: 5

Rep: Reputation: 0
Calling perl script and passing variable from php script

Can someone help me please. I am writing php script and thought of combining it with perl because other function can easily processed by perl. I have no problem with calling perl from php.

The following worked fine.
PHP Code:
echo exec('./'); 
However the problem I have is to pass variable to perl.

I tried the following:
PHP Code:
echo exec('./',$variable);
and all failed.

Is there a way of passing variable to perl?
Old 03-29-2007, 01:56 AM   #2
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,293

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335

Add a space between the command and the variable. If the variable contains spaces, you also need to use the escapeshellarg function.

exec('./'.' '.EscapeShellArg($variable));

The second parameter to exec will be filled with the commands output by the way. See
Old 03-29-2007, 03:07 AM   #3
Senior Member
Registered: Mar 2004
Location: england
Distribution: Debian, Mint, Puppy, Raspbian
Posts: 3,421

Rep: Reputation: 200Reputation: 200Reputation: 200
in the perl script use the -s switch.
then you can do:
exec('./ foo=bar');
in perl script
#!/usr/bin/perl -s
use vars ($foo);

if $foo do_something;
I like this sort of thing in a non-interactive script as it makes the options
explicit and obvious for future maintainers.
Old 04-02-2007, 10:49 AM   #4
LQ Newbie
Registered: Apr 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks bigearsbilly and Guttorm for the solution. I am now smiling

It works!!
Old 10-21-2008, 07:25 AM   #5
LQ Newbie
Registered: Oct 2008
Posts: 1

Rep: Reputation: 0
I would be very instersted to know how you made it works.

i have got a php script with this (test1.php)

PHP Code:
exec('./ $foo');


and a perl script with this:

#!/usr/bin/perl -s
use vars ($foo);

if ($foo eq bar){
	print $foo;
What i am trying to achieve is just to print out the content of the variable.

The idea behind that, is php front end sending the filename to the perl script to process.

Does it make sense ?

Thanks for any replys
Old 10-21-2008, 08:01 AM   #6
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 5,390

Rep: Reputation: 409Reputation: 409Reputation: 409Reputation: 409Reputation: 409
In this case, why not use $ARGV[0] ?

print $ARGV[0];


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
Passing a variable to a cgi script WindowBreaker Slackware 1 04-03-2006 10:02 PM
Passing parameters to PERL script paddyjoy Programming 3 03-07-2006 11:04 AM
Bash Script Passing variable to Function nutthick Programming 2 02-02-2005 05:15 AM
calling a c++ binary inside a perl script Blue_muppet Programming 3 08-28-2004 11:31 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:07 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration