Run a php script in ruby on rails

后端 未结 4 920
长情又很酷
长情又很酷 2020-12-19 16:15

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.

The php file loca

相关标签:
4条回答
  • 2020-12-19 16:42

    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.

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

    Why not rewrite the script in ruby?

    0 讨论(0)
  • 2020-12-19 16:53

    well, does system('php public/php_script.php') work?

    0 讨论(0)
  • 2020-12-19 17:00

    Try `php #{RAILS_ROOT}/public/php_script.php` or %x["php #{RAILS_ROOT}/public/php_script.php"]

    System command doesn't work in rails but some code like the above should be ok.

    0 讨论(0)
  • 2020-12-19 17:00

    My problem solved by this line in my Controller

    result = D:\\rails\\php\\php.exe -f D:\\Rails\\rails_apps\\project\\public\\df.php po

    0 讨论(0)
提交回复
热议问题