从 PHP 执行 Ruby 脚本并获取输出 [英] Executing Ruby script from PHP and getting output

查看:60
本文介绍了从 PHP 执行 Ruby 脚本并获取输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 Ruby 脚本 (test.rb):

I have this Ruby script (test.rb):

print "hello"

我有这个 PHP 脚本 (test.php):

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

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

现在我通过 CLI 调用我的 PHP 脚本:

Now I call my PHP script from CLI this way:

php test.php

我没有输出(它应该打印你好")

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

为什么?

推荐答案

system 将捕获 ruby​​ 脚本的输出.

system would capture the output of the ruby script.

您可能想要这样做:

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

这篇关于从 PHP 执行 Ruby 脚本并获取输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆