dongshukou0240 2011-05-18 14:00
浏览 98
已采纳

如何从ruby脚本将$ _POST值传递给php脚本

I need to run a cron job to add a svn repository using reposman.rb for Redmine. But we also have a php script (with an interface) that enable us to create repositories automaticly.

The php script receives a $_POST value, create the repos, sets permissions, assign some group for read and write access to the newly created repos.

My question is this:

  1. how could I execute the php script, instead of the svnadmin create command in reposman.rb?
  2. How can I give a $_POST parameter to the php script, so it could setup my svn repos correctly, using the php script.

Thanks

Edit: Here are some example of what both scripts do.

Ruby script:

...
// Add the repos
system "svnadmin create #{path}"
...

Php script:

// Receive the name of the repos to add
$dir= $_POST["dir"]; 
// Do all the stuff with the permissions
$cmd= "sudo /usr/local/bin/createsvnrepo $dir";
system("$cmd", $retval);
...
  • 写回答

6条回答 默认 最新

  • dongyong1897 2011-06-02 16:14
    关注

    Since, @Richard Knop's comment helped me more than any answer, I will answer my own question to help others.

    I used curb to send a post to the php script.

    reposman.rb

    ...
    # Added at start of file.
    require 'rubygems'
    require 'curb'
    ...
    
    # Replace the creation of repos from 
    module SCM
        module Subversion
            def self.create(path)
                system_or_raise "svnadmin create #{path}"
            end
        end
        ...
    end
    
    # to 
    module SCM
        module Subversion
            def self.create(path)
                Curl::Easy.http_post(
                    "http://example.com/customCreaterepos.php", # Url to the php script
                    Curl::PostField.content('reposName', path)) # Index of php $_POST in script
            end
        end
        ...
    end
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容