Forum: IronRuby Where is open-uri and why it does not work?

Posted by Mohammad Azam (azamsharp)
on 2009-06-22 16:51
I have been trying this for weeks now and still no answer. The open-uri
is messed up in IronRuby. Why does it always keep opening a file and not
the URL?
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 16:53
Here is the error messages:


C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\r
uby\1.8>ir
IronRuby 0.5.0.0 on .NET 2.0.50727.3053
Copyright (c) Microsoft Corporation. All rights reserved.

>>> require 'open-uri'
:0:in `require': no such file to load -- stringio (LoadError)
        from ./open-uri.rb:2
        from :0
        from :0:in `require'
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 16:57
Why stringio is not present in the same folder as 'open-uri'?
Posted by Jim Deville (Guest)
on 2009-06-22 17:15
(Received via mailing list)
StringIO is written in C#, so it is part of IronRuby.Libraries.dll. This 
is because Ruby's StringIO has C extensions.

JD

...there is no try
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 17:18
What?????

I am talking about 'open-uri' and when I run this:

ir myapp.rb

It throws the exception that it is missing uri and stringio. Why all the 
libraries are not put in the same folder why are they distributed in 
many different folders?

And there is a file called 'stringio.rb'


Jim Deville wrote:
> StringIO is written in C#, so it is part of IronRuby.Libraries.dll. This 
> is because Ruby's StringIO has C extensions.
> 
> JD
> 
> ...there is no try
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 17:23
The libraries required by open-uri to function properly are spread up in 
two different folders:

paths.Add(@"C:\ironruby\ironruby\Merlin\Main\Languages\Ruby\Libs");
            paths.Add(@"C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8");


WHY?
Posted by Jim Deville (Guest)
on 2009-06-22 17:31
(Received via mailing list)
The file stringio.rb (the correct one) has the following in it:
# 
****************************************************************************
#
# Copyright (c) Microsoft Corporation.
#
# This source code is subject to terms and conditions of the Microsoft 
Public License. A
# copy of the license can be found in the License.html file at the root 
of this distribution. If
# you cannot locate the  Microsoft Public License, please send an email 
to
# ironruby@microsoft.com. By using this source code in any fashion, you 
are agreeing to be bound
# by the terms of the Microsoft Public License.
#
# You must not remove this notice, or any other, from this software.
#
#
# 
****************************************************************************

load_assembly 'IronRuby.Libraries', 'IronRuby.StandardLibrary.StringIO'

There are two library paths in IronRuby. One is the redistribution of 
most of the Ruby Standard library. This is the 
C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8 
folder. The other is IronRuby specific files to load C-based standard 
libraries (such as stringio.rb) and stub files to make .NET specific 
assemblies easier to load (such as System.Windows.Forms.rb).

For me, the following works from the IronRuby console. Can you send me 
the output of it when you try to run it from ir.exe?

C:\vsl\m1\Merlin\Main\Bin\Debug
[26] > ir.exe
IronRuby 0.5.0.0 on .NET 2.0.50727.4908
Copyright (c) Microsoft Corporation. All rights reserved.

>>> puts $:
c:/vsl/m1/Merlin/Main/Languages/Ruby/libs/
c:/vsl/m1/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/site_ruby/1.8/
c:/vsl/m1/Merlin/External.LCA_RESTRICTED/Languages/Ruby/redist-libs/ruby/1.8/
.
=> nil
>>> require 'open-uri'
=> true
>>> u = open("http://www.google.com")
=> #<StringIO:0x00000a6 @base_uri=#<URI::HTTP:0x0000096 
URL:http://www.google.com>, @meta={"proxy-connection"=>"Keep-Ali
ve", "connection"=>"Keep-Alive", "transfer-encoding"=>"chunked", 
"via"=>"1.1 RED-PRXY-27", "expires"=>"-1", "date"=>"Mon
, 22 Jun 2009 15:30:20 GMT", "content-type"=>"text/html; 
charset=ISO-8859-1", "server"=>"gws", "cache-control"=>"private
, max-age=0", 
"set-cookie"=>"PREF=ID=eb7ab68a47c1cfc2:TM=1245684620:LM=1245684620:S=NVRnVXhGZ3bM1DuD; 
expires=Wed, 22-Ju
n-2011 15:30:20 GMT; path=/; domain=.google.com"}, @status=["200", 
"OK"]>
>>> puts u
#<StringIO:0x00000a6>
=> nil
>>> u.close
=> nil
>>> exit


Thanks,

JD

...there is no try
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 17:37
Thanks for the detailed explanation!

The steps that you have provided worked!

But the main question is that if I am using my project from a different 
directory like C:\RubyProject\ and I am also running IR.exe from 
C:\RubyProject then how will it find open-uri.

It always says 'not able to locate open-uri' file. If I manually add 
'open-uri' to c:\rubyproject\libs then it complains not able to find 
'uri'


Posted by Jim Deville (Guest)
on 2009-06-22 17:50
(Received via mailing list)
Does it work if you copy open-uri.rb, uri.rb and the uri directory to 
C:\rubyproject\libs?

JD

...there is no try
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 17:53
Nope it does not work:

Here is the code:

require 'libs/System.Windows.Forms'
require 'libs/System.Drawing'
require 'libs/open-uri'

The libs folder contains uri.rb which is taken from

C:\ironruby\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\ruby-1.8.6p287\lib\ruby\1.8

folder.

And here is the error:

C:\IronRubyProjects\IronRubyTaskListApplication>ir rss_reader_form.rb
:0:in `require': no such file to load -- uri (LoadError)
        from ./libs/open-uri.rb:1
        from rss_reader_form.rb:3
        from :0:in `require'




Posted by Jim Deville (Guest)
on 2009-06-22 17:58
(Received via mailing list)
What does puts $: output in that situation? I'm wondering why you have 
"require 'libs/open-uri'" instead of "require 'open-uri'"

JD

...there is no try
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 18:00
It is outputing the following:


>>> puts $:
C:/WINDOWS/system32
Posted by Jim Deville (Guest)
on 2009-06-22 18:05
(Received via mailing list)
Is this one of our releases? Or is it a build from the git sources? In 
both cases you should have an ir.exe.config that sets both the libs 
folder and the redist-libs folder into your load path.  Any idea why 
yours doesn't?

JD

...there is no try
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 18:09
This is downloaded from Git!

I have the ir.exe.config file with the following path setup:

 <options>
      <set language="Ruby" option="LibraryPaths" 
value="..\..\Languages\Ruby\libs\;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\site_ruby\1.8\;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8\" 
/>
    </options>

The location of this file is:

C:\ironruby\ironruby\Merlin\Main\bin\Debug

My project location is C:\IronRubyProjects\IronRubyTaskListApplication.

I am running the IR.EXX from 
C:\IronRubyProjects\IronRubyTaskListApplication and then it complains 
about the open-uri file. I put the open-uri file in the libs folder then 
is complains about uri file. I put the uri file and uri folder in the 
libs folder but it still complains about the uri file.



Posted by Mohammad Azam (azamsharp)
on 2009-06-22 18:10
I have even tried running ir.exe from my projects folder:


C:\IronRubyProjects\IronRubyTaskListApplication>ir
IronRuby 0.5.0.0 on .NET 2.0.50727.3053
Copyright (c) Microsoft Corporation. All rights reserved.

>>> require 'open-uri'
:0:in `require': no such file to load -- open-uri (LoadError)
        from :0
Posted by Jim Deville (Guest)
on 2009-06-22 18:14
(Received via mailing list)
Can you run c:\ironruby\ironruby\Merlin\Main\bin\debug\ir.exe 
C:\IronRubyProjects\IronRubyTasksApplication\foo.rb (where foo is the 
startup file for your program)?

JD

...there is no try
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 18:16
I should also mention one thing which is that I placed my ir.exe and 
some other files that are required by ir.exe in System32 folder so that 
I can access it from anywhere in the directory.
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 18:18
No I cannot run it because it require Windows.Forms and Windows.Drawing 
modules. If I add those modules then it will work:



C:\ironruby\ironruby\Merlin\Main\bin\Debug>ir.exe 
C:\IronRubyProjects\IronRubyTa
skListApplication\main_form.rb
C:\ironruby\ironruby\Merlin\Main\Languages\Ruby\Libraries.LCA_RESTRICTED\Builtin
s\KernelOps.cs:423:in `require': no such file to load -- 
libs/System.Windows.For
ms (LoadError)
        from 
C:/IronRubyProjects/IronRubyTaskListApplication/main_form.rb:2
Posted by Jim Deville (Guest)
on 2009-06-22 18:20
(Received via mailing list)
A better way to do that, in this case, is to just add 
c:\ironruby\ironruby\Merlin\Main\bin\debug to your %PATH%

JD

...there is no try
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 18:21
How do I do that?
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 18:21
Should I also remove ir.exe from System32?
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 18:26
I have added the path to System Variables. The name of RUBYLIBS and the 
value is c:\ironruby\ironruby\Merlin\Main\bin\debug.

Here is the code:

require 'libs/System.Windows.Forms'
require 'libs/System.Drawing'
require 'open-uri'

And still giving the same issues:



C:\IronRubyProjects\IronRubyTaskListApplication>ir rss_reader_form.rb

C:\IronRubyProjects\IronRubyTaskListApplication>ir rss_reader_form.rb
:0:in `require': no such file to load -- open-uri (LoadError)
        from rss_reader_form.rb:3
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 18:31
I have set up the PATH variable in System Variables to 
C:\ironruby\ironruby\Merlin\Main\bin\Debug

But now windows command prompt is not picking up the ir.exe file!
Posted by Mohammad Azam (azamsharp)
on 2009-06-22 18:34
Finally I got it!

I closed the command prompt and ran it again and now everything is 
working. Even the open-uri started working.

Thanks for all your help!

The PATH was a good solution to go :)
Posted by Jim Deville (Guest)
on 2009-06-22 18:39
(Received via mailing list)
Glad that it worked :)

JD

...there is no try
Posted by Jim Deville (Guest)
on 2009-06-22 18:41
(Received via mailing list)
Remove the RUBYLIBS variable, and then change require 
'libs/System.Windows.Forms' to require 'System.Windows.Form'. Do the 
same for System.Drawing, then let me know how it goes. You shouldn't 
need to set any Ruby environment variables, since ir.exe.config should 
set everything up for you right now.

JD

...there is no try
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.