David Morales
David Morales

Reputation: 18064

Executing Ruby script from PHP and getting output

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?

Upvotes: 2

Views: 6455

Answers (2)

Nakkeeran
Nakkeeran

Reputation: 15296

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);
?>

Upvotes: 0

RageZ
RageZ

Reputation: 27313

system would capture the output of the ruby script.

you might want to do:

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

Upvotes: 7

Related Questions