ruby - Open executable and manage its streams? -


i'm trying open ruby script prompts stuff popen3, testing purposes.

i need able type stdin of proccess , inspect outputs. far have this:

require 'open3' def run(executable, opts = {})   signal.trap('cld')     puts 'stdin:', @stdout.readlines     # @stderr.rewind     puts 'stderr:', @stderr.readlines     # got eof, trying rewind gives me 'errno::espipe: illegal seek'      [@stdin, @stdout, @stderr].each &:close   end    @stdin, @stdout, @stderr, @thread = open3.popen3(executable)   @status = @thread.value end 

have been trying days, brain melting.

the things allowed in signal handler limited. example, you not allowed i/o in signal handler. signal handlers notoriously easy wrong.

what think using open3.capture*? avoids blocks/race conditions when reading stdout , stderr @ same time. besides, allows pass data stdin. use keyword argument :stdin_data!


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -