Lamp
Lamp

Reputation: 1084

Passing arguments in php script inside ruby

In my ruby code, i am using Backticks (`) to execute a php script like:

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

How can i pass arguments in this php script?

How can i grab the arguments inside the (php) script?

thanks!

Upvotes: 1

Views: 305

Answers (1)

Pekka
Pekka

Reputation: 449823

Check out Using PHP from the command line in the PHP manual.

This page has a full example:

 # 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"
}

Upvotes: 2

Related Questions