0

Help.I am in need of using a ruby script for my website.I am very new to ruby, and I only need to use single gem(anystyle-parser) for my ruby script, and so I decided to use php to create the website.

My PHP code :

<?php
    if (isset($_POST["ref"])) {
    $reference=$_POST["ref"];
    echo "OUTPUT :";
    echo "<br>";
    $cmd="ruby test.rb ".escapeshellarg($reference);
    echo system($cmd);
    }
    else
    {}  

My ruby code :

require 'anystyle/parser'
require 'rubygems'
ref=ARGV[0]
s=Anystyle.parse ref
puts s

Gem requirements:

anystyle/parser

The value from PHP code is getting passed to the ruby script(through escapeshellarg),but it does not seem to execute the function of the 'anystyl-parser' gem.

How do I create a link between the apache localhost server and the rubygems?

The ruby script script works fine in the terminal.But it is not working ,when called through the php(in the localhost).

Gobi S
  • 1
  • 3
  • Did you check, whether something on stderr has been written? Maybe GEMPATH is not set correctly and Ruby doesn't find the Gem. – user1934428 Mar 22 '16 at 06:45
  • How should i set the gem path??If i execute the ruby code in the terminal,it is working properly.But, if i try to execute the very same code using system() in PHP, it is not executing the ruby code. – Gobi S Mar 22 '16 at 07:17
  • Please switch on displaying errors using [this method](http://stackoverflow.com/a/21429652/1544012) and tell us what errors you get. How have you installed your ruby - is it installed from system package or using RVM or any other method? – BoraMa Mar 22 '16 at 08:51
  • Only error number 22527 is being displayed for me.And, all the packages have been installed from system package.Ruby is working fine(accessible via terminal), and I've also installed rubygems and all the other necessary gems.Gems are present in /var/lib/gems/2.1.0/gems/.Ruby version is 2.1.5.Thank you. – Gobi S Mar 22 '16 at 09:52
  • @GobiS: Did you verify, whether GEMPATH (and/or GEMHOME) are set differently in both invocations? This would be the first step.... – user1934428 Mar 24 '16 at 12:10
  • I haven't set any of those two(above as you have said) anywhere.Just want to know how i should do that. – Gobi S Mar 24 '16 at 18:18

0 Answers0