2

I have this Ruby script (test.rb):

print "hello"

And I have this PHP script (test.php):

$cmd = "ruby test.rb";
system($cmd);

Now I call my PHP script from CLI this way:

php test.php

And I get no output (it should print "hello")

Why?

RageZ
  • 26,800
  • 12
  • 67
  • 76
David Morales
  • 17,816
  • 12
  • 77
  • 105

2 Answers2

7

system would capture the output of the ruby script.

you might want to do:

$cmd = "ruby test.rb";
echo system($cmd);
RageZ
  • 26,800
  • 12
  • 67
  • 76
  • yes, OK, without the echo is working fine, the PHP CLI I was using was misconfigured, but now I have open another question with the real problem: http://stackoverflow.com/questions/8604637/executing-sass-script-from-php-and-getting-output – David Morales Dec 22 '11 at 13:37
  • what about if i want to run with a different user other than root. This code is running perfectly on local system but watir is not supporting for run through root user. Can you suggest @RageZ – Vipin Singh Feb 22 '18 at 09:26
0

Its working for me, check whether both ruby script and php in the same folder and installed ruby in your machine

<?php
$cmd = "ruby test.rb";     
system($cmd);
?>
Nakkeeran
  • 15,296
  • 1
  • 21
  • 22