title: PHP to execute a Ruby script and capture the JSON result
body: <p>I have to work with a Ruby script that is dependent on a Gem. When the script is executed a JSON object is returned.</p>
  
  <p>I am successfully executing the script using the following code.</p>
  
  <pre><code>&lt;?php
  
  $ruby = 'ruby ruby/teams.rb';
  
  $res = system($ruby);
  
  var_dump(json_decode($res, true));
  </code></pre>
  
  <p>The following is an example response from <code>ruby/teams.rb</code></p>
  
  <pre><code>{"status"=&gt;"active", "teamId"=&gt;"XPLFKS59PK" }
  </code></pre>
  
  <p>My problem is that this printed directly to the screen and is not capture in the variable <code>$res</code>. When using <code>var_dump(json_decode($res, true))</code> I get <code>null</code>.</p>
  
  <p>What I would like to be able to do is capture the JSON response in the <code>$res</code> variable so I can convert to an array and worth with the data.</p>
  
  <p>Any ideas if this is possible?</p>