Hi! I'm working on Linux station. I would like to replace variable value into a Perl Script. I know this shell command:
perl -pi -e \'s/FirstWordToChange/ByThisOne/g\' FileName
And I've tried to launch it in my PHP script like this:
system("perl -pi -e \'s/FirstWordToChange/ByThisOne/g\' FileName");
Or
exec("perl -pi -e \'s/FirstWordToChange/ByThisOne/g\' FileName");
the variables I must replace the values are in a Perl Script which I Run later :
exec(perl FileName >file.log); //this one works very good
how can I procede?
How to Replace Character into a File with PHP
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
In essence PHP won't communicate with perl... you'll need to have the perl script output something to SDOUT so that PHP can read it and parse it. This probably works the same the other way, unless you pass the variables as command line arguments and read them from $argv.
I usually use backticks to execute a shell command...
I wonder why you need a 'temporary' file.. Simply use the 'modified program' as the input for the second call to perl -e...
Code: Select all
<?php
`/usr/bin/perl -e 'my perl code'`;
?>Perl Script
ok ok. thanks to you two. I think I'm going to change the perl code. I'll use arguments and I'll run just one perl script:
<?php
`/usr/bin/perl -e'My_perl_code $arg1 $arg2 ......'
?>

<?php
`/usr/bin/perl -e'My_perl_code $arg1 $arg2 ......'
?>