From: Marcin Raczkowski Date: 2007-04-19T22:50:13+09:00 Subject: Re: Executing program from ruby On Thursday 19 April 2007 13:34, James Edward Gray II wrote: > On Apr 19, 2007, at 8:21 AM, Marcin Raczkowski wrote: > > any expirience with open4? help? pointers? > > TextMate uses a hand-rolled popen3(), which is really just an open4() > clone. Allan Odgaard, the creator of TextMate, wrote the code, but > it's straightforward enough that I thought it might help you to see it: > > def my_popen3(*cmd) # returns [stdin, stdout, strerr, pid] > pw = IO::pipe # pipe[0] for read, pipe[1] for write > pr = IO::pipe > pe = IO::pipe > > pid = fork{ > pw[1].close > STDIN.reopen(pw[0]) > pw[0].close > > pr[0].close > STDOUT.reopen(pr[1]) > pr[1].close > > pe[0].close > STDERR.reopen(pe[1]) > pe[1].close > > exec(*cmd) > } > > pw[0].close > pr[1].close > pe[1].close > > pw[1].sync = true > > [pw[1], pr[0], pe[0], pid] > end > > Hope that helps. > > James Edward Gray II code is really simmilar to opn4 i understand how it works (i follow "don't use wizard/library you don't understand " rule) ... and to be honest i can write it myself, but i thought there's solution for problem already :] well popen 3/4 is almost good enought .. but if you use it with block it doesn't check if command was executed at all!!! i need to do something like this: check if command exists... try to run it... if there's problem (no privilages etc.) do some work about that , notify user etc. if program started write to it's stdin and get answer. popen4 should do exactly that .. but sample that should rise error doesn't do that, not to mention there's no documentation except changelog and few samples. thnx for reply tho -- Marcin Raczkowski --- Friends teach what you should know Enemies Teach what you have to know