From: Klaus Spreckelsen Date: 2003-05-13T23:53:19+09:00 Subject: Re: RCR for child execution Aredridel wrote: > On Mon, 2003-05-12 at 17:57, nobu.nokada@softhome.net wrote: >> Hi, >> >> At Tue, 13 May 2003 08:47:36 +0900, >> ahoward wrote: >> > > I don't like this notation. But I like the idea of spawning child >> > > with its stdin/out/err replaced. >> > spawn 'command', :out => io, :err => io >> >> spawn ['command', 'arg1', 'arg 2'], :out => io, :err => io > > spawn 'command' do > out = io > err = io > end.run => <#ExternalProc:0x0000> > > -- make it a full block, so that it's easily extensible. spawn could be > a factory for ExternalProc objects (an alias for ExternalProc.new?). Some months ago, I have written an class just for this purpose. Simple example: require "cp" x = ConnectedProcess.new("cat") do |i, o, e| $stdin.reopen i $stdout.reopen o end x.start x.stdin.puts "hello" puts x.stdout.gets # -> hello x = ConnectedProcess.popen2("ls", "not_there") do |i, o, _, pid| puts "Process #{pid}: #{o.gets}" # -> Process 17245: ls: not_there: No such file or directory end You can find the class an the demo under http://www.tp1.ruhr-uni-bochum.de/~ks/cp/ Unfortunatly, the documentation is currently available only in German. Klaus Spreckelsen