# How to call a c bin from a controller

**URL:** <https://www.ruby-forum.com/t/how-to-call-a-c-bin-from-a-controller/131910>\
**Category:** Rails\
**Created:** [March 14, 2008, 10:07am UTC](https://www.ruby-forum.com/t/how-to-call-a-c-bin-from-a-controller/131910 "2008-03-14T10:07:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ecrevisse06](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/838e76/32.png) [@Ecrevisse06](https://www.ruby-forum.com/u/Ecrevisse06)\
**Post date:** [March 14, 2008, 10:07am UTC](https://www.ruby-forum.com/t/how-to-call-a-c-bin-from-a-controller/131910/1 "2008-03-14T10:07:14Z")

</div>

Hi,  
I am a newbee and for my project i have to call a C bin from the cgi-  
bin rep of my host ,i want to call the script from my  
controller…I’am sure it’s a trivial question but i havent found the  
answer on google, I hope that someone could show my the right  
solution,

here the Php script to call the CGI I want to do something like that  
in my rails app

function urlSPPlus($urlCGI)

{  
$handle = fopen($urlCGI, “rb”);  
if (!$handle) { return “Error cgi script.”; }  
$contents = fgetss($handle, 2048);  
fclose($handle);  
list($debut,$url,$fin) = split("’", $contents, 3);  
return $url;  
}

---

<div class="post-metadata">

**Author:** ![Ecrevisse06](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/838e76/32.png) [@Ecrevisse06](https://www.ruby-forum.com/u/Ecrevisse06)\
**Post date:** [March 14, 2008, 10:12am UTC](https://www.ruby-forum.com/t/how-to-call-a-c-bin-from-a-controller/131910/2 "2008-03-14T10:12:32Z")

</div>

On 14 Mar 2008, at 09:06, Ecrevisse06 wrote:

> Hi,  
> I am a newbee and for my project i have to call a C bin from the cgi-  
> bin rep of my host ,i want to call the script from my  
> controller…I’am sure it’s a trivial question but i havent found the  
> answer on google, I hope that someone could show my the right  
> solution,

IO.popen is probably what you want.

Fred

---

<div class="post-metadata">

**Author:** ![Ecrevisse06](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/838e76/32.png) [@Ecrevisse06](https://www.ruby-forum.com/u/Ecrevisse06)\
**Post date:** [March 17, 2008, 12:52pm UTC](https://www.ruby-forum.com/t/how-to-call-a-c-bin-from-a-controller/131910/3 "2008-03-17T12:52:21Z")

</div>

Thanks Fred, for yout help

But I think I don’t undesrtand something I have made some test

cgi-bin/hello.rb=\> simple hello world  
so in my controller:  
IO.popen(“…/…/…/cgi-bin/hello.rb”, “w+”) do |pipe|  
pipe.close\_write  
output = pipe.read  
@output=output  
end  
in my view  
\<%=@output%\> =\> “hello world”  
its ok

but when i use the same script for the hmac\_demo.exe (the real cgi  
given by my bank)  
the result in my view is an error with pipe.puts “my params”

text/html Status: 0 Unknown Request Method  
Error 407 Unknown Request Method  
Only POST or GET request methods are available

So I made a new test like that :  
@urlcgihmac = “…/…/…/cgi-bin/hmac\_wahine\_decoration.exe”  
@urlhmac = “#{@urlcgihmac}?  
montant=#{@montant}&reference=#{@reference}&email=#{@email}&langue=#{@langue}&moyen=#{@moyen}&modalite=#{@modalite}”  
IO.popen(“#{@urlhmac}”, “w+”)  
…ect

but with that in my view I’haven’t got any result

please help me!

On Mar 14, 10:11 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
