problem using ruby with c++

T

Teofilo Dutra

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++ ?
 
T

Teofilo Dutra

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();

...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top