[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Help on I/O pipe

Ara.T.Howard

1/3/2006 2:32:00 PM

2 Answers

Sky Yin

1/3/2006 10:55:00 PM

0

Thank Yohanes for the detailed explanation. I've just tried using

io = IO.popen("optimizer.exe", "r+")
io.puts "..." #stdin<model.mod
io.gets #stdout
...
io.close

It's weird that first two io.gets worked OK to retrieve the first two lines
of the result, but then io.gets halted on the third io.gets. No clue.

As for the session gem, I installed, but require 'session' simply returns a
false under Win32.

Thanks anyway.


On 1/3/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
>
> On Tue, 3 Jan 2006, Sky Yin wrote:
>
> > One process of my analysis program uses an external non-linear
> optimizer.
> > That optimizer needs a model file as the argument. The current approach
> I
> > employ to accomplish this is to create a model file on disk everytime
> > running the optimizer. The code is simply like
> >
> > @model = File.open("model.mod", "w")
> > ...
> > @model.close
> > result = `optimizer.exe model.mod`
> >
> > The problem is that I have to repeat running optimizer on different
> models
> > many many times during the analysis. I wonder if such heavy writing on a
> > single file will do any harm to my hard disk. My concern of improving it
> is
> > to use I/O pipe to feed the optimizer without the needs to create real
> model
> > files. Can anyone give me some tips or examples on using the shell pipe?
> The
> > rdoc isn't so clear.
> >
> > Thanks
>
> assuming that your analysis code can read it's input sequentially you
> might
> want to try session:
>
> require 'session'
>
> sh = Session::new
>
> model_input = ...
>
> stdout, stderr = sh.execute 'optimizer.exe', 'stdin' => model_input
>
> p sh.exitstatus
>
> regards.
>
> -a
> --
>
> ===============================================================================
> | ara [dot] t [dot] howard [at] noaa [dot] gov
> | all happiness comes from the desire for others to be happy. all misery
> | comes from the desire for oneself to be happy.
> | -- bodhicaryavatara
>
> ===============================================================================
>
>
>


--
Blog >>> http://spaces.msn.com/members/s...

Sky Yin

1/4/2006 1:58:00 AM

0

It works very smoothly now. Thanks a lot for the timely help.
Everyday I love ruby a bit more :^)

On 1/3/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
>
> On Wed, 4 Jan 2006, Sky Yin wrote:
>
> > Thank Yohanes for the detailed explanation. I've just tried using
> >
> > io = IO.popen("optimizer.exe", "r+")
> > io.puts "..." #stdin<model.mod
> > io.gets #stdout
> > ...
> > io.close
> >
> > It's weird that first two io.gets worked OK to retrieve the first two
> lines
> > of the result, but then io.gets halted on the third io.gets. No clue.
> >
> > As for the session gem, I installed, but require 'session' simply
> returns a
> > false under Win32.
> >
> > Thanks anyway.
>
> session is not going to work under win32. you'll need to do something
> like
>
> io = IO.popen("optimizer.exe", "r+")
>
> io.puts "..." # stdin<model.mod
>
> io.close_write
>
> stdout = io.read
>
> io.close
>
> to avoid hanging on a gets with line buffered output.
>
> regards.
>
> -a
> --
>
> ===============================================================================
> | ara [dot] t [dot] howard [at] noaa [dot] gov
> | all happiness comes from the desire for others to be happy. all misery
> | comes from the desire for oneself to be happy.
> | -- bodhicaryavatara
>
> ===============================================================================
>
>
>


--
Blog >>> http://spaces.msn.com/members/s...