在ruby中的php脚本中传递参数

时间:2010-11-11 16:51:02

标签: php ruby-on-rails ruby

在我的ruby代码中,我使用Backticks(`)来执行像以下的PHP脚本:

result = `php #{RAILS_ROOT}/lib/php/test.php`

如何在这个php脚本中传递参数?

我如何获取(php)脚本中的参数?

谢谢!

1 个答案:

答案 0 :(得分:2)

在PHP手册中查看Using PHP from the command line

This page有一个完整的例子:

 # This will not execute the given code but will show the PHP usage
$ php -r 'var_dump($argv);' -h
Usage: php [options] [-f] <file> [args...]
[...]

# This will pass the '-h' argument to your script and prevent PHP from showing it's usage
$ php -r 'var_dump($argv);' -- -h
array(2) {
  [0]=>
  string(1) "-"
  [1]=>
  string(2) "-h"
}
相关问题