在Rails中的ruby中运行一个php脚本 [英] Run a php script in ruby on rails

查看:129
本文介绍了在Rails中的ruby中运行一个php脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Rails应用程序之一中,我需要从Ruby on Rails应用程序的Controller中执行一个PHP文件. PHP文件用于进行一些数据库编辑.

In one of my Rails application I need to execute a PHP file from the Controller of Ruby on Rails app. The PHP file meant for some database editing.

位于我的公共"文件夹中的php文件

The php file located in my "public" folder

有什么办法吗?

推荐答案

如果您想以某种方式与该流程进行交流,请使用 .或者,您可以使用backticks选项(在此处使用标记不容易),该选项返回进程写入标准输出的字符串.如果不需要通信,则system "php <script>"会在命令成功的任何地方返回true或false,并且您没有机会进行进一步的通信.

If you want to talk to the process in some way, use IO.popen("php <script>"). Or you could use the backticks option (not easy with the markup here), which returns the string the process writes to stdout. If you need no communication, system "php <script>" returns you true or false wherever the command succeded and you've got no chance to communicate further.

如果输入的内容不安全,请使用Array#shelljoin对其进行转义.

If you have unsafe input, use Array#shelljoin to escape it.

为什么不用ruby重写脚本?

Why not rewrite the script in ruby?

这篇关于在Rails中的ruby中运行一个php脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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