[Q] Problem with popen on WIn32 (1.8.x)

Can anybody tell me why the following Ruby code that uses popen doesn't work at all on my Windows XP (Pro SP1) machine, ruby 1.8.2 preview2 or 1.8.1?

you.rb

···

------
while true
   sleep 1
   puts "This line should print in me.rb"
end

me.rb
-----
pig = IO.popen("ruby.exe you.rb", "w+")

while true
   pig.gets
end

Launch me.rb and you'll see that no output is showing at all. On Linux it works like a charm.

If you succeed in making this work can you tell me which version of Ruby and Windows you are using?

Thanks for all your help

Laurent

perhaps putting STDOUT.sync = true in you.rb might help??

-a

···

On Sat, 23 Oct 2004, Laurent Julliard wrote:

Can anybody tell me why the following Ruby code that uses popen
doesn't work at all on my Windows XP (Pro SP1) machine, ruby 1.8.2
preview2 or 1.8.1?

you.rb
------
while true
  sleep 1
  puts "This line should print in me.rb"
end

me.rb
-----
pig = IO.popen("ruby.exe you.rb", "w+")

while true
  pig.gets
end

Launch me.rb and you'll see that no output is showing at all. On Linux
it works like a charm.

If you succeed in making this work can you tell me which version of
Ruby and Windows you are using?

Thanks for all your help

Laurent

--

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
When you do something, you should burn yourself completely, like a good
bonfire, leaving no trace of yourself. --Shunryu Suzuki

===============================================================================

"Laurent Julliard" <laurent@moldus.org> schrieb im Newsbeitrag news:417979EB.7090107@moldus.org...

Can anybody tell me why the following Ruby code that uses popen doesn't work at all on my Windows XP (Pro SP1) machine, ruby 1.8.2 preview2 or 1.8.1?

you.rb
------
while true
  sleep 1
  puts "This line should print in me.rb"
end

me.rb
-----
pig = IO.popen("ruby.exe you.rb", "w+")

while true
  pig.gets
end

Launch me.rb and you'll see that no output is showing at all. On Linux it works like a charm.

If you succeed in making this work can you tell me which version of Ruby and Windows you are using?

Thanks for all your help

:-))) You forgot the "puts" in me.rb. For me, this works:

you.rb

while true
   sleep 1
   puts "This line should print in me.rb"
end

me.rb

pig = IO.popen("ruby.exe you.rb", "w+")

while true
   puts pig.gets
end

If you're not patient, then you should use synchronized output, i.e. switch on flushing of every line like this in the first line of me.rb:

$defout.sync=true

Otherwise it'll take some time until the pipe fills and you see first results on the reader side. But when they come they come in chunks of several lines.

Btw, I'd use the block form to ensure proper cleanup and used flag "r" because we want to read only here. (I know that this is useless in this case, but IMHO it's better to start with the better pattern right from the start. Can save you some time later when you don't have to hunt down strange bugs.) So I had written me.rb like this:

me2.rb

IO.popen("ruby.exe you.rb", "r") do |pig|
  while ( line = pig.gets )
    puts line
  end
end

Kind regards

    robert

Hi,

At Sat, 23 Oct 2004 06:21:54 +0900,
Laurent Julliard wrote in [ruby-talk:117409]:

Can anybody tell me why the following Ruby code that uses popen
doesn't work at all on my Windows XP (Pro SP1) machine, ruby 1.8.2
preview2 or 1.8.1?

It may be a recently fixed bug.

···

--
Nobu Nakada

I tried that already but it doesn't make a difference. However if you remove the sleep statement it works!!!??? Any idea ?

Laurent

···

Ara.T.Howard@noaa.gov wrote:

perhaps putting STDOUT.sync = true in you.rb might help??

Robert Klemme wrote:

"Laurent Julliard" <laurent@moldus.org> schrieb im Newsbeitrag news:417979EB.7090107@moldus.org...

Can anybody tell me why the following Ruby code that uses popen doesn't work at all on my Windows XP (Pro SP1) machine, ruby 1.8.2 preview2 or 1.8.1?

you.rb
------
while true
  sleep 1
  puts "This line should print in me.rb"
end

me.rb
-----
pig = IO.popen("ruby.exe you.rb", "w+")

while true
  pig.gets
end

Launch me.rb and you'll see that no output is showing at all. On Linux it works like a charm.

If you succeed in making this work can you tell me which version of Ruby and Windows you are using?

Thanks for all your help

:-))) You forgot the "puts" in me.rb. For me, this works:

you.rb

while true
  sleep 1
  puts "This line should print in me.rb"
end

me.rb

pig = IO.popen("ruby.exe you.rb", "w+")

while true
  puts pig.gets
end

I forgot the puts while copy-pasting the code but even with the puts it doesn't make any difference. It still doesn't work on 1.8.2 preview 2/XP. Which version on Ruby/Windows are you using?

Laurent

···

--
Laurent JULLIARD
http://www.moldus.org/~laurent

"Laurent Julliard" <laurent@moldus.org> schrieb im Newsbeitrag news:4179F49D.6010109@moldus.org...

Robert Klemme wrote:

"Laurent Julliard" <laurent@moldus.org> schrieb im Newsbeitrag news:417979EB.7090107@moldus.org...

Can anybody tell me why the following Ruby code that uses popen doesn't work at all on my Windows XP (Pro SP1) machine, ruby 1.8.2 preview2 or 1.8.1?

you.rb
------
while true
  sleep 1
  puts "This line should print in me.rb"
end

me.rb
-----
pig = IO.popen("ruby.exe you.rb", "w+")

while true
  pig.gets
end

Launch me.rb and you'll see that no output is showing at all. On Linux it works like a charm.

If you succeed in making this work can you tell me which version of Ruby and Windows you are using?

Thanks for all your help

:-))) You forgot the "puts" in me.rb. For me, this works:

you.rb

while true
  sleep 1
  puts "This line should print in me.rb"
end

me.rb

pig = IO.popen("ruby.exe you.rb", "w+")

while true
  puts pig.gets
end

I forgot the puts while copy-pasting the code but even with the puts it doesn't make any difference.

How long did you wait to see any output? With "sleep 1" it takes considerable time until the pipe is full and the first chunk of messages appear - on my machine it's just above 30 seconds.

It still doesn't work on 1.8.2 preview 2/XP. Which version on Ruby/Windows are you using?

Robert@Babelfish2 ~
$ uname -a
CYGWIN_NT-5.1 Babelfish2 1.5.10(0.116/4/2) 2004-05-25 22:07 i686 unknown unknown Cygwin

Robert@Babelfish2 ~
$ ruby -v
ruby 1.8.1 (2003-12-25) [i386-cygwin]

Robert@Babelfish2 ~
$ cmd /c ver

Microsoft Windows XP [Version 5.1.2600]

(SP2 installed)

Kind regards

    robert