[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

problem using ruby with c++

Teofilo Dutra

12/4/2007 4:46:00 PM

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

Hi,

I'm trying to use a ruby script in c++ which uses the method get of a
Net::HTTP object,
when I run it(script) in prompt it works, but when I run it in C++ it
returns an error in the get line.

ruby :

require "net/http"

#
# some code...
#

page = "www.somepage.com"
port = 80
param = "someparam"

conn = Net::HTTP.new(page,port)
resp,data = conn.get(param) # get line :P

#
# some code...
#

c++ :

ruby_init();
ruby_script("script");

char *args[] =
{
"param",
NULL
};

ruby_set_argv((sizeof(args) / sizeof(args[0])) - 1, args);

ruby_init_loadpath();
rb_load_file("script.rb");
int status = ruby_exec();

ruby_cleanup(status);
ruby_finalize();

Error :

../lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo: non-recoverab
le failure in name resolution. (SocketError) from
d:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect' from
d:/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout' from
d:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout' from
d:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect' from
d:/ruby/lib/ruby/1.8/net/http.rb:553:in `do_start' from
d:/ruby/lib/ruby/1.8/net/http.rb:542:in `start' from
d:/ruby/lib/ruby/1.8/net/http.rb:1029:in `request' from
d:/ruby/lib/ruby/1.8/net/http.rb:769:in `get' from script.rb:53

What's missing ? or What's wrong ? Why does the script work in prompt and
not work in C++ ?

1 Answer

Teofilo Dutra

12/4/2007 10:03:00 PM

0

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

I solved the problem, the method NtInitialize() was missing before
ruby_init()

right code:

int argc = 0;
char **argv = 0;

NtInitialize(&argc,&argv);

ruby_init();

...

2007/12/4, Teofilo Dutra <teofilo.dutra@gmail.com>:
>
> Hi,
>
> I'm trying to use a ruby script in c++ which uses the method get of a
> Net::HTTP object,
> when I run it(script) in prompt it works, but when I run it in C++ it
> returns an error in the get line.
>
> ruby :
>
> require "net/http"
>
> #
> # some code...
> #
>
> page = "www.somepage.com"
> port = 80
> param = "someparam"
>
> conn = Net::HTTP.new(page,port)
> resp,data = conn.get(param) # get line
> :P
>
> #
> # some code...
> #
>
> c++ :
>
> ruby_init();
> ruby_script("script");
>
> char *args[] =
> {
> "param",
> NULL
> };
>
> ruby_set_argv((sizeof(args) / sizeof(args[0])) - 1, args);
>
> ruby_init_loadpath();
> rb_load_file("script.rb");
> int status = ruby_exec();
>
> ruby_cleanup(status);
> ruby_finalize();
>
> Error :
>
> ../lib/ruby/1.8/net/http.rb:560:in `initialize': getaddrinfo:
> non-recoverab
> le failure in name resolution. (SocketError) from
> d:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect' from
> d:/ruby/lib/ruby/1.8/timeout.rb:48:in `timeout' from
> d:/ruby/lib/ruby/1.8/timeout.rb:76:in `timeout' from
> d:/ruby/lib/ruby/1.8/net/http.rb:560:in `connect' from
> d:/ruby/lib/ruby/1.8/net/http.rb:553:in `do_start' from
> d:/ruby/lib/ruby/1.8/net/http.rb:542:in `start' from
> d:/ruby/lib/ruby/1.8/net/http.rb:1029:in `request' from
> d:/ruby/lib/ruby/1.8/net/http.rb:769:in `get' from script.rb:53
>
> What's missing ? or What's wrong ? Why does the script work in prompt and
> not work in C++ ?
>