Hi,
I am trying to open an external process that normally reads and writes from
stdin/to stdout. For opening a pipe to this process I am using IO.popen.
Reading each line from the pipe is no problem until it comes to a point where
the external process wants to get some data from stdin and it waits for input.
Now when I write something into the IO stream I need to call IO#close_write for
further reading. But since the pipe is closed now, I cannot write to it any
more.
For example:
– snip –
pipe = IO.popen(“ruby -r debug script.rb”, “w+”)
if pipe
while line = pipe.gets
line.chomp!
puts line
if line =~ /^script.rb:\d+:.+$/ # Regexp to find special lines
# Here I want to tell the debugger what to do and
# get further output to evaluate.
pipe.puts "next"
pipe.close_write
end
end
– snap –
Is there any way to reopen the pipe at the position where I close it or is there
any way to avoid using IO#close_write so I can write more commands to the
debugger?
Greetings, Dario
try this:
http://raa.ruby-lang.org/list.rhtml?name=session
it will do that, and more. what you describe is EXACTLY why i wrote this,
when you need to send muliple commands to an external process and de-multiplex
the responses (output). you also get stderr.
-a
···
On 23 Apr 2004, Dario Linsky wrote:
Hi,
I am trying to open an external process that normally reads and writes from
stdin/to stdout. For opening a pipe to this process I am using IO.popen.
Reading each line from the pipe is no problem until it comes to a point where
the external process wants to get some data from stdin and it waits for input.
Now when I write something into the IO stream I need to call IO#close_write for
further reading. But since the pipe is closed now, I cannot write to it any
more.
For example:
– snip –
pipe = IO.popen(“ruby -r debug script.rb”, “w+”)
if pipe
while line = pipe.gets
line.chomp!
puts line
if line =~ /^script.rb:\d+:.+$/ # Regexp to find special lines
# Here I want to tell the debugger what to do and
# get further output to evaluate.
pipe.puts "next"
pipe.close_write
end
end
– snap –
Is there any way to reopen the pipe at the position where I close it or is there
any way to avoid using IO#close_write so I can write more commands to the
debugger?
Greetings, Dario
–
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: http://www.ngdc.noaa.gov/stp/
TRY :: for l in ruby perl;do $l -e “print “\x3a\x2d\x29\x0a””;done
===============================================================================
Does your lib work on Windows? Could it work with win32_popen?
Guillaume.
···
On Fri, 2004-04-23 at 11:24, Ara.T.Howard wrote:
On 23 Apr 2004, Dario Linsky wrote:
Hi,
I am trying to open an external process that normally reads and writes from
stdin/to stdout. For opening a pipe to this process I am using IO.popen.
Reading each line from the pipe is no problem until it comes to a point where
the external process wants to get some data from stdin and it waits for input.
Now when I write something into the IO stream I need to call IO#close_write for
further reading. But since the pipe is closed now, I cannot write to it any
more.
For example:
– snip –
pipe = IO.popen(“ruby -r debug script.rb”, “w+”)
if pipe
while line = pipe.gets
line.chomp!
puts line
if line =~ /^script.rb:\d+:.+$/ # Regexp to find special lines
# Here I want to tell the debugger what to do and
# get further output to evaluate.
pipe.puts "next"
pipe.close_write
end
end
– snap –
Is there any way to reopen the pipe at the position where I close it or is there
any way to avoid using IO#close_write so I can write more commands to the
debugger?
Greetings, Dario
try this:
http://raa.ruby-lang.org/list.rhtml?name=session
it will do that, and more. what you describe is EXACTLY why i wrote this,
when you need to send muliple commands to an external process and de-multiplex
the responses (output). you also get stderr.
-a
===============================================================================
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: http://www.ngdc.noaa.gov/stp/
TRY :: for l in ruby perl;do $l -e “print “\x3a\x2d\x29\x0a””;done
===============================================================================
Does your lib work on Windows? Could it work with win32_popen?
i would happy to try to make it do so, but currently it does not…
does win32_popen return fd’s for stdin, stdout, AND stderr?
i don’t have access to a window’s machine but the source is pretty straight
forward - basically all you need to do is look for the call to open3 and put
something else in there… other than that it should work.
-a
···
On Sat, 24 Apr 2004, Guillaume Marcais wrote:
Guillaume.
On Fri, 2004-04-23 at 11:24, Ara.T.Howard wrote:
On 23 Apr 2004, Dario Linsky wrote:
Hi,
I am trying to open an external process that normally reads and writes from
stdin/to stdout. For opening a pipe to this process I am using IO.popen.
Reading each line from the pipe is no problem until it comes to a point where
the external process wants to get some data from stdin and it waits for input.
Now when I write something into the IO stream I need to call IO#close_write for
further reading. But since the pipe is closed now, I cannot write to it any
more.
For example:
– snip –
pipe = IO.popen(“ruby -r debug script.rb”, “w+”)
if pipe
while line = pipe.gets
line.chomp!
puts line
if line =~ /^script.rb:\d+:.+$/ # Regexp to find special lines
# Here I want to tell the debugger what to do and
# get further output to evaluate.
pipe.puts "next"
pipe.close_write
end
end
– snap –
Is there any way to reopen the pipe at the position where I close it or is there
any way to avoid using IO#close_write so I can write more commands to the
debugger?
Greetings, Dario
try this:
http://raa.ruby-lang.org/list.rhtml?name=session
it will do that, and more. what you describe is EXACTLY why i wrote this,
when you need to send muliple commands to an external process and de-multiplex
the responses (output). you also get stderr.
-a
===============================================================================
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: http://www.ngdc.noaa.gov/stp/
TRY :: for l in ruby perl;do $l -e “print “\x3a\x2d\x29\x0a””;done
===============================================================================
–
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: http://www.ngdc.noaa.gov/stp/
TRY :: for l in ruby perl;do $l -e “print “\x3a\x2d\x29\x0a””;done
===============================================================================