From: Gennady Date: 2003-05-28T13:47:21+09:00 Subject: Re: system calls Again, I am kind of unsure that it is worth posting to RAA, no good documentation, no formal installation and so on. Meanwhile, I am attaching URL here. If you find it useful, please let me know. Along with it, I am copying a brief description from my first post on the subject: http://homepage.mac.com/bystr/Development/Ruby/launch.rb === Recently I implemented a facility for such cases and if you are interested I can send it to you (I am not sure it is worth enough to be sent to RAA). It does not spawn threads, all is done with IO#select. I called it "launch" and made it available through the Kernel. So in your case it can be used as: require 'launch' messages = launch "date" It returns an array of message arrays, the first element -- messages read from the command's stdout, the second -- from the stderr. If the command is killed or returns with error (return code is not 0), exception TerminateError is raised. If you rescue it, you can get the reason for termination (signal or non-zero return) and the return code (signal number if killed). Stderr messages are also available from the exception class. In general, it was designed for launching a pipeline of commands with access to all error messages and return codes from all commands in the pipeline. Unfortunately, when you do it with system("command1 | command2 |command3"), you may not even know that command1 or command2 terminated abnormally as shell returns the code of the last command in a pipeline. General syntax is: launch [, ] [, ... [, ] { | line_0, line_1, ... line_N | block } -> anArray - an optional IO object. If specified, the first command's stdin will be redirected from this IO object. Otherwise "/dev/null" is used. - all commands are spawned (fork & exec) with stdout of the previous command redirected to stdin of the next command. Stdout of the last command is read out and messages are stored in the array available as the first element of the returned array. All other elements of the returned array store error messages from stderr's of all commands respectively. If a block is specified, lines read from stdout of the last command and stderrs of all command are made available to the block immediately (messages are not stored in the returned array): line_0 (if not nil) is a line from stdout of the last command, line_1 .. line_N (if not nils) are lines read from stderrs of command_1 ... command_N respectively. Only one line passed to the block is not nil. I use the block form when I need to show the progress of a long running Unix command (like tar). ====== On Tuesday, May 27, 2003, at 07:44 PM, Pe�a, Botp wrote: > Gennady [mailto:bystr@mac.com] wrote: >> Recently I implemented a facility for such cases and if you are >> interested I can send it to you (I am not sure it is worth >> enough to be >> sent to RAA). It does not spawn threads, all is done with IO#select. >> >> I called it "launch" and made it available through the Kernel. So in >> your case it can be used as: >> >> require 'launch' >> messages = launch "date" > > can you post it on raa, pls. It looks useful to me and I'd like to see > the > code. > > kind regards -botp >