Windows and Ruby - Not very good friends?

I am new to Ruby and RoR, so pardon me if I ask naive questions.

Ruby on Windows just does not feel right to me. Primarily, I develop in
Linux, mostly in Fedora. Though, I have Ubuntu installed on some
machines as well. I do get stuck in Linux too, mostly due to my lack of
knowledge and experience with Ruby and RoR, but have much better batting
average finding my way around the problems. I have a dual boot machine
with Windows and Fedora. So I decided to go through the "Programming
Ruby" book on the Windows side just for the heck of it -- I keep running
into problems that I have no idea how to fix.

Here is another one:

This is a little program out of the PickAxe book (2nd Edition) on page
108.

  opfile_name = "C:\\RubyPrograms\\PickAxeBook\\testfile"
  socket = $stdin
  op_file = File.open(opfile_name, "w")
  begin
    # Exceptions raised by this code will
    # be caught by the following rescue clause
    while data = socket.read(512)
      op_file.write(data)
    end

  rescue SystemCallError
    $stderr.print "IO failed: " + $!
    op_file.close
    File.delete(opfile_name)
    raise
  end

When I run it, a nice little DOS window opens up with
C:\ruby\bin\ruby.exe it its title bar and the cursor just waits. I
cannot type, cannot CNTRL-C, except close it by clicking on the top
right hand corner X box. When I do, ruby quits with the following
message:

ruby ex0261.rb
Exit code: -1073741510

How does one go about debugging this? I can't even tell which line of
the code the program is hung-up at?

I can see that windows/ruby is creating the testfile in the directory
which has zero bytes. I thought that the line socket = $stdin assigns
standard input to this input stream which we call socket. Therefore, am
I not supposed to be able to type into the Waiting DOS window that opens
up? Is this not the Standard Input?

I haven't tried to run this in Linux yet, but something tells me that I
am better off in that environment? May be my lack of
experience/knowledge?

Please advise.

Bharat

···

--
Posted via http://www.ruby-forum.com/\.

Well... I couldn't duplicate your problem at first. I copied and pasted
your code and it ran fine on my machine (after I changed the path). It even
seems to have done what it was supposed to - opened the file, wrote 512
chars to it etc. (btw, how would one cause the exception to be raised?
invalid characters?)

Then I realized you might be trying to do it from within SciTe. try doing
it from a command prompt.

···

On 2/10/07, Bharat Ruparel <bruparel@mercury.com> wrote:

I am new to Ruby and RoR, so pardon me if I ask naive questions.

Ruby on Windows just does not feel right to me. Primarily, I develop in
Linux, mostly in Fedora. Though, I have Ubuntu installed on some
machines as well. I do get stuck in Linux too, mostly due to my lack of
knowledge and experience with Ruby and RoR, but have much better batting
average finding my way around the problems. I have a dual boot machine
with Windows and Fedora. So I decided to go through the "Programming
Ruby" book on the Windows side just for the heck of it -- I keep running
into problems that I have no idea how to fix.

Here is another one:

This is a little program out of the PickAxe book (2nd Edition) on page
108.

  opfile_name = "C:\\RubyPrograms\\PickAxeBook\\testfile"
  socket = $stdin
  op_file = File.open(opfile_name, "w")
  begin
    # Exceptions raised by this code will
    # be caught by the following rescue clause
    while data = socket.read(512)
      op_file.write(data)
    end

  rescue SystemCallError
    $stderr.print "IO failed: " + $!
    op_file.close
    File.delete(opfile_name)
    raise
  end

When I run it, a nice little DOS window opens up with
C:\ruby\bin\ruby.exe it its title bar and the cursor just waits. I
cannot type, cannot CNTRL-C, except close it by clicking on the top
right hand corner X box. When I do, ruby quits with the following
message:

>ruby ex0261.rb
>Exit code: -1073741510

How does one go about debugging this? I can't even tell which line of
the code the program is hung-up at?

I can see that windows/ruby is creating the testfile in the directory
which has zero bytes. I thought that the line socket = $stdin assigns
standard input to this input stream which we call socket. Therefore, am
I not supposed to be able to type into the Waiting DOS window that opens
up? Is this not the Standard Input?

Bharat,

Don't give up on Ruby on Windows so quickly. I've been using it on
Windows for years, but maybe I just don't know what I'm missing...

Anyway, when I tried that code, everything worked fine. What version
of ruby are you running and on what version of Windows?

You should be able to type in the terminal that comes up. $stdin
isn't be redirected.

If you can get that working, I found that changing the while block to:

  while data = socket.read(1)
    op_file.write(data)
    op_file.flush
  end

better demonstrates the apparent point of this program (writing $stdin
to a file), as the buffer gets flushed as often as you hit enter. 512
bytes seemed excessive.

Chris

···

On Feb 10, 7:27 pm, Bharat Ruparel <brupa...@mercury.com> wrote:

I am new to Ruby and RoR, so pardon me if I ask naive questions.

Ruby on Windows just does not feel right to me. Primarily, I develop in
Linux, mostly in Fedora. Though, I have Ubuntu installed on some
machines as well. I do get stuck in Linux too, mostly due to my lack of
knowledge and experience with Ruby and RoR, but have much better batting
average finding my way around the problems. I have a dual boot machine
with Windows and Fedora. So I decided to go through the "Programming
Ruby" book on the Windows side just for the heck of it -- I keep running
into problems that I have no idea how to fix.

Here is another one:

This is a little program out of the PickAxe book (2nd Edition) on page
108.

  opfile_name = "C:\\RubyPrograms\\PickAxeBook\\testfile"
  socket = $stdin
  op_file = File.open(opfile_name, "w")
  begin
    # Exceptions raised by this code will
    # be caught by the following rescue clause
    while data = socket.read(512)
      op_file.write(data)
    end

  rescue SystemCallError
    $stderr.print "IO failed: " + $!
    op_file.close
    File.delete(opfile_name)
    raise
  end

When I run it, a nice little DOS window opens up with
C:\ruby\bin\ruby.exe it its title bar and the cursor just waits. I
cannot type, cannot CNTRL-C, except close it by clicking on the top
right hand corner X box. When I do, ruby quits with the following
message:

>ruby ex0261.rb
>Exit code: -1073741510

How does one go about debugging this? I can't even tell which line of
the code the program is hung-up at?

I can see that windows/ruby is creating the testfile in the directory
which has zero bytes. I thought that the line socket = $stdin assigns
standard input to this input stream which we call socket. Therefore, am
I not supposed to be able to type into the Waiting DOS window that opens
up? Is this not the Standard Input?

I haven't tried to run this in Linux yet, but something tells me that I
am better off in that environment? May be my lack of
experience/knowledge?

Please advise.

Bharat

--
Posted viahttp://www.ruby-forum.com/.

I just saw Jason Mayer's response in ruby-talk-google. I bet he's
right about running it via SciTE. Try running it from the command
line.

···

On Feb 10, 7:27 pm, Bharat Ruparel <brupa...@mercury.com> wrote:

I am new to Ruby and RoR, so pardon me if I ask naive questions.

Ruby on Windows just does not feel right to me. Primarily, I develop in
Linux, mostly in Fedora. Though, I have Ubuntu installed on some
machines as well. I do get stuck in Linux too, mostly due to my lack of
knowledge and experience with Ruby and RoR, but have much better batting
average finding my way around the problems. I have a dual boot machine
with Windows and Fedora. So I decided to go through the "Programming
Ruby" book on the Windows side just for the heck of it -- I keep running
into problems that I have no idea how to fix.

Here is another one:

This is a little program out of the PickAxe book (2nd Edition) on page
108.

  opfile_name = "C:\\RubyPrograms\\PickAxeBook\\testfile"
  socket = $stdin
  op_file = File.open(opfile_name, "w")
  begin
    # Exceptions raised by this code will
    # be caught by the following rescue clause
    while data = socket.read(512)
      op_file.write(data)
    end

  rescue SystemCallError
    $stderr.print "IO failed: " + $!
    op_file.close
    File.delete(opfile_name)
    raise
  end

When I run it, a nice little DOS window opens up with
C:\ruby\bin\ruby.exe it its title bar and the cursor just waits. I
cannot type, cannot CNTRL-C, except close it by clicking on the top
right hand corner X box. When I do, ruby quits with the following
message:

>ruby ex0261.rb
>Exit code: -1073741510

How does one go about debugging this? I can't even tell which line of
the code the program is hung-up at?

I can see that windows/ruby is creating the testfile in the directory
which has zero bytes. I thought that the line socket = $stdin assigns
standard input to this input stream which we call socket. Therefore, am
I not supposed to be able to type into the Waiting DOS window that opens
up? Is this not the Standard Input?

I haven't tried to run this in Linux yet, but something tells me that I
am better off in that environment? May be my lack of
experience/knowledge?

Please advise.

Bharat

--
Posted viahttp://www.ruby-forum.com/.

Bharat Ruparel schrieb:

...

ruby ex0261.rb
Exit code: -1073741510

...

This is a typical problem when running a program from inside "SciTE" and and an input request occurs. This exit code "-1073741510" will be produced by the one-liner "gets".

In this case it is necessary to open a windows console and start the program by "ruby <program>" or simply by typing "<program>.rb" (the program name including the extension), because the extension is registered an ruby will be started automatically.

But - the shebang will NOT work in a windows environment at all.

Wolfgang Nádasi-Donner

what is the equivalent to isNaN in ruby?

Gents,
First, thank you all for your time and quick responses. I am beginning
to see why people are flocking to ruby besides the language itself and
the RoR framework. It is the wonderful community help eco-system
surrounding it. May be with your help, I can come up to speed and start
helping others.

Second, you are right. I am running it from SciTe. In Linux world, I
am more comfortable at the shell prompt and open up a number of shell
windows. Moreover, I am always editing with either vim or sometimes
gedit and as a result, running the ruby programs from the command
prompt. That has to be the reason why I haven't run into these kinds of
obscure problems yet, especially dealing with standard input/output.

I ran the program from the command prompt and it waits for my input and
I can type on the terminal as much as I want. However, I don't know how
to signal the termination of the standard input. I tried CTRL-C which
is obviously the termination of the program. since I see that in the
stack trace as follows:

ex0261.rb:7:in `read': Interrupt
        from ex0261.rb:7

The seventh line of the code in the program above is:

    while data = socket.read(1)

Chris, as you suggested, I changed the buffer count to 1 instead of 512,
but still no go. I type the text and hit the enter key but windows just
waits for me to enter text. I guess it boils down to generating end of
the input signal to windows. In unix/linux it is CTRL-D, which does not
work in windows.

Wolfgang, you wrote:
"the shebang will NOT work in a windows environment at all."
You mean in: $stderr.print "IO failed: " + $!
right? Is there any other way I can write something which works in both
Windows and Linux in a cross-platform manner?
Thanks again and regards to you all.
Bharat

···

--
Posted via http://www.ruby-forum.com/.

Float#nan?

···

On 2/11/07, Vincent Franco <vincent-franco@comcast.net> wrote:

what is the equivalent to isNaN in ruby?

Bharat Ruparel schrieb:

However, I don't know how to signal the termination of the standard input.

It is <CNTL>+Z or <CNTL>+D in a Windows console (I don't know which one, both work in the example below).

C:\Dokumente und Einstellungen\wolfgang>ruby
puts "hello"
^Z
hello

C:\Dokumente und Einstellungen\wolfgang>ruby
puts "hello"
^D
hello

Wolfgang, you wrote:
"the shebang will NOT work in a windows environment at all."
You mean in: $stderr.print "IO failed: " + $!
right?

No, I mean the typical first line in Unix/Linux programs, which start the correct interpreter automatically. This kind of invocation does not work in a Windows environment.

Wolfgang Nádasi-Donner

Thanks Wolfgang.
Bharat

···

--
Posted via http://www.ruby-forum.com/.

Follow-up question for Chris, Wolfgang, and anyone else who has
experience in this matter. Chris, you wrote above:

"Don't give up on Ruby on Windows so quickly. I've been using it on
Windows for years, but maybe I just don't know what I'm missing..."

I was primarily interested in "mildly" testing Ruby cross-platform
claims something similar to Java (I come from the Java world) and Perl
(I am not a Perl programmer, though have a healthy respect for its
capabilities. I do Bash and Ksh however). Moreover, my interest in
Ruby is motivated by a desire to get up to speed in Ruby on Rails which
I intend to use do develop database driven web applications on
open-source platforms. My question to you all is: have you found a
good reason (or reasons) to use Ruby on Windows to do any real
commercial work? Or is it because Windows is so all pervasive? I
guess I am looking for some real-life examples of how Ruby is helping do
some heavy-lifting in the Windows world. Just curious.
Bharat

···

--
Posted via http://www.ruby-forum.com/.

Bharat Ruparel schrieb:

My question to you all is: have you found a good reason (or reasons) to use Ruby on Windows to do any real commercial work?

Well, I started to build some libraries and techniques for textual analysis. To describe details will be to much for here (in addition I am too lazy up to now to write there a lot about it) - the ideas were taken from longer experience with software adaption and maintenance tools which were build long ago in Berlin.

Ruby's "irb" is a very helpful tool, together with Ruby's flexibility to change classes in the middle of a session, and all capabilities to define Methods for some objects. This makes it possible to build dynamic categories of object groups, in addition to the class hierarchy.

These techniques will the be used for textual data analysis and systematic editing. It is clearly necessary to have this available for the platforms customers will use,...

Or is it because Windows is so all pervasive?

... and usually Windows PCs are present everywhere.

Wolfgang Nádasi-Donner

I work in a windows world. I learned ruby to attempt to automate my job,
but in doing so, I learned that ruby was so intuitive I could attempt to
jump from doing tech support to programming.

···

On 2/11/07, Bharat Ruparel <bruparel@mercury.com> wrote:

My question to you all is: have you found a
good reason (or reasons) to use Ruby on Windows to do any real
commercial work?

It depends on whether the output of your effort is (1) a Ruby application
that you ship to windows clients or whether (2) Ruby is used in the
development of windows-deployed apps (i.e. in automated testing,
development tools, but Ruby code is not shipped to customers).

For (2) Ruby is great. Really great for all the reasons you have already
discussed.

For (1) though, Ruby is a bit of a mixed bag. Client applications require
a mix of windowing kits, and this can make for some very byzantine
installation options. In general, if it doesn't look like windows on a windows
OS that works against you.

Rails hosting on windows doesn't appear to have
the scalability of the Unix options, and you will have to work harder
to get it. You also miss a lot of the interesting stuff available to Unix
railsers (like an easier-to-install RMagick (basically graphics), and
good stuff like Capistrano). A Rails corporate intranet application
could be quite successful on Windows hardware, but if your company
is large I would just host it on Unix hardware.

···

On 2/11/07, Bharat Ruparel <bruparel@mercury.com> wrote:

My question to you all is: have you found a
good reason (or reasons) to use Ruby on Windows to do any real
commercial work? Or is it because Windows is so all pervasive?