PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > problem using ruby with c++
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
problem using ruby with c++

Réponse
 
LinkBack Outils de la discussion
Vieux 04/12/2007, 17h45   #1
Teofilo Dutra
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut problem using ruby with c++

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

  Réponse avec citation
Vieux 04/12/2007, 23h02   #2
Teofilo Dutra
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: problem using ruby with c++

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


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h43.


Édité par : vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,98583 seconds with 10 queries