Calling PHP from Ruby and reading STDOUT

PHP and Ruby syntax are far enough apart that I was loathe to attempt a port of some working PHP scripts in my arsenal, but I needed to call said scripts from a relatively complex Ruby program. Fast & dirty integration of this type is generally performed using a system call, but unlike most things Ruby I didn't find the Ruby way in this case to be all that intuitive.
The %x technique for the system call made it easy to read the output of my PHP program into a variable in the calling script. The real trick was finding the correct syntax for passing a parameter to the %x call as shown below.
Learn from my studies grasshopper:
avariableparameter = "--o ipso -v lorem"result = %x[php /path/to/script.php "#{avariableparameter}"]
Share Comments